Say I have a document like this and I want a voter count:
post { voters: [1, 2, 7, 6] }
I can't increment a separate counter like voterCount without reading the record before updating it to check for duplicates, so when writing I just want to use $addToSet.
But then, on the read side, if all I want is the count of post.voters there doesn't seem to be any way to get it without loading the (possibly very large) list of voters, only to do a .size() on the array and throw it out.
It seems to me like there should be something like slice, but for count:
db.posts.find({}, {voters:{$slice: 5}}) // first 5 voters
db.posts.find({}, {voters:{$count: 1}}) // return count of voters instead of voters array
Is a feature like that in the works, or is there another solution I'm missing?
--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com
See also the IRC channel -- freenode.net#mongodb