这方面似乎缺乏 mongoDB API 文档。我正在尝试使用聚合函数来获取某个集合中流行标签的数量。这是我希望执行的命令:
db.runCommand(
{ aggregate : "articles",
pipeline : [ { $unwind : "$Tags" },
{ $group : { _id : "$Tags", count : { $sum : 1 } }
} ]});
Run Code Online (Sandbox Code Playgroud)
当我使用 shell 执行此操作时,我得到以下信息:
{
"result": [{
"_id": "2012",
"count": 3
}, {
"_id": "seattle",
"count": 5
}],
"ok": 1
}
Run Code Online (Sandbox Code Playgroud)
我正在使用 c# 4.0,所以我想我更愿意将它作为动态对象取回来,但我会尽我所能......
FWIW,我使用 mongoDB for Windows,32 位,v2.1.1(每晚)