With the mongoDB C# driver, how do I issue a runCommand?(使用MongoDB C#驱动程序,我如何发出runCommand?)
问题描述
MongoDB API文档似乎缺少这方面的内容。我正在尝试使用Aggregate函数来获取某个集合中流行标签的计数。以下是我希望执行的命令:
db.runCommand(
{ aggregate : "articles",
pipeline : [ { $unwind : "$Tags" },
{ $group : { _id : "$Tags", count : { $sum : 1 } }
} ]});
当我使用外壳执行此命令时,我得到以下结果:
{
"result": [{
"_id": "2012",
"count": 3
}, {
"_id": "seattle",
"count": 5
}],
"ok": 1
}
我使用的是C#4.0,所以我想我会把它作为一个动态对象取回,但我会取我能得到的任何东西...
FWIW,我使用的是MongoDB for Windows,32位,v2.1.1(夜间)
推荐答案
对应的C#驱动文档页面:RunCommand()。所以基本上你调用Database.RunCommand("MyCommand")
。对于需要(多个)属性的更复杂命令的示例,JIRA中的此票证可能会很方便:CSHARP-478
这篇关于使用MongoDB C#驱动程序,我如何发出runCommand?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!