Is there any way to get the number of unique categories without getting the whole return set and counting the number of documents (and is that even possible with the mongo shell)?
Stephen Lee
unread,
Jan 25, 2013, 3:23:27 PM1/25/13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
Both your suggestion, using the aggregation framework, and mine require using the full collection, but using the distinct command should be a more direct query.
Adam Fields
unread,
Jan 30, 2013, 11:55:16 PM1/30/13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
> Adam, have you tried using the distinct command, http://docs.mongodb.org/manual/reference/method/db.collection.distinct/#db.collection.distinct? Something like db.documents.distinct('category_id').toArray().length?
>
> Both your suggestion, using the aggregation framework, and mine require using the full collection, but using the distinct command should be a more direct query.
That looks like it might do exactly what I need. I'll check it out. Thanks!
Ronald Stalder
unread,
Jan 31, 2013, 6:50:36 AM1/31/13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mongod...@googlegroups.com
don't use toArray() - just distinct(...).length (distinct returns an array)