Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有以下收藏:
{ "comments" : [{"text" : "z"},{"text" : "b"}] } { "comments" : [{"text" : "a"}] }
每个集合元素都有一个comments带有评论数组的属性。
comments
如何计算我收藏中的所有评论?此收藏有 3 条评论
我不想计算我的收藏长度。
你试过:
db.collection.aggregate( [ { $unwind: "$comments" }, { $group: { _id: "$_id", sum: { $sum: 1 } } } ]);