Mongodb SortByCount并显示每个文档
我想知道,除了我的代码所做的以外,是否还有可能显示每个被计数的文档Mongodb SortByCount并显示每个文档,mongodb,mongodb-query,Mongodb,Mongodb Query,我想知道,除了我的代码所做的以外,是否还有可能显示每个被计数的文档 db.getCollection('mflix_movies').aggregate([ {"$unwind" : "$countries"}, {"$sortByCount" : "$countries" } ]) 这是上述查询的结果: /* 1 */ { "_id" : "USA"
db.getCollection('mflix_movies').aggregate([
{"$unwind" : "$countries"},
{"$sortByCount" : "$countries" }
])
这是上述查询的结果:
/* 1 */
{
"_id" : "USA",
"count" : 11855
}
/* 2 */
{
"_id" : "France",
"count" : 3093
}
/* 3 */
{
"_id" : "UK",
"count" : 2904
}
/* 4 */
{
"_id" : "Germany",
"count" : 1659
}
我还想展示美国的11855份文件,法国的3093份文件等等。。。我希望在每次计数的底部显示此信息我找到了答案:
db.getCollection('mflix_movies').aggregate([
{ $unwind : "$countries" },
{ $group: { _id: '$countries', Films: { $push: { Titre: '$title' } }, Total: { $sum: 1 }}},
{ $sort: { Total: -1 } }
])
你的问题不清楚,你能详细说明一下吗=>例如,我想要更多的11855。我编辑过,更清楚吗?你确定吗?这不是一个好主意,如果在一个文档中添加数千个文档,它将超过16MB的内存限制,请参阅。