简体   繁体   English

mongo查询,用于选择集合中所有唯一ID的计数

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

In mongodb, I have a comments database with a collection of comments. 在mongodb中,我有一个包含评论集合的评论数据库。 Each comment has a "videoId" field that represents which video the comment belongs to. 每个评论都有一个“ videoId”字段,代表该评论所属的视频。 How do I write a query that selects all unique videoId and count the number of occurrences for each unique videoId? 如何编写查询以选择所有唯一的videoId并计算每个唯一的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? 由于我的Web应用程序是基于Spring框架构建的,因此现有的数据库调用是通过mongodb通过Spring Datastore完成的……使用基于Mongo JSON的查询方法和字段限制,该查询将是什么样?

Thanks! 谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM