开发者

mongo query for selecting count of all unique ids in a collection

In mongodb, I have a comments database with a collection of comments. Each comment has a "videoId" field that represents which video the comment belongs to. How do I write 开发者_Python百科a query that selects all unique videoId and count the number of occurrences for each unique videoId? I basically want a count of the number of comments per video.

Since my web application is built on the Spring framework, the existing database calls are done through Spring Datastore with mongodb... what would that query look like with Mongo JSON based query methods and field restrictions?

Thanks!


It is exactly a map reduce use case.

see : http://cookbook.mongodb.org/patterns/unique_items_map_reduce/ and http://cookbook.mongodb.org/patterns/count_tags/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜