我有一个大约400gb的mongodb.文档包含各种字段,但这里的关键是一个IDarray.
所以json文件可能是这样的
{
"name":"bob"
"dob":"1/1/2011"
"key":
[
"1020123123",
"1234123222",
"5021297723"
]
}
这里的焦点变量是"键".5000万个文档中总共有大约100亿个密钥(因此每个文档大约有200个密钥).密钥可以重复,大约有1500万个唯一密钥.
我想做的是返回10000把最常用的 keys .我以为聚合可以做到这一点,但我很难让它运行.这是我的代码:
db.users.aggregate(
[
{ $unwind : "$key" },
{ $group : { _id : "$key", number : { $sum : 1 } } },
{ $sort : { number : -1 } },
{ $limit : 10000 }
]
);
知道我做错了什么吗?