use*_*940 4 .net c# mongodb c#-4.0 mongodb-.net-driver
这方面似乎缺乏 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(每晚)
这是相应的 C# 驱动程序文档页面:RunCommand()。所以基本上你打电话Database.RunCommand("MyCommand")。对于需要(多个)属性的更复杂命令的示例,JIRA 中的此票证可能会派上用场:CSHARP-478
| 归档时间: |
|
| 查看次数: |
8663 次 |
| 最近记录: |