I have a collection of people documents which look like this:
{u'name': u'... FirstName LastName ...',u'clubs': [ ... list of
dicts ...], u'_id': ObjectId('... object id value ...')}
I'd like to be able to query the most active people based on the
number of the clubs they belong to. Ideally, I'd like to use sort,
like this:
db.people.find().sort('clubs.length', -1).limit(10)
but instead of getting the top ten people by the number of clubs, that
query ignores the length property of the inner clubs array, and just
returns the first 10 docs in the collection, regardless of the clubs
length.
I have gotten this to work by using a map reduce structure instead,
but it seems sort() would be better and simpler for this type of
query.
The sort documentation (
http://www.mongodb.org/display/DOCS/Advanced
+Queries#AdvancedQueries-{{sort%28%29}}) makes no mention of how to do
it, so is there some undocumented syntax to get it to work this way?