gpt4 book ai didi

c# - 使用 mongoDB C# 驱动程序,如何发出 runCommand?

转载 作者:可可西里 更新时间:2023-11-01 09:12:35 26 4
gpt4 key购买 nike

mongoDB API 文档似乎缺少这方面的内容。我正在尝试使用聚合函数来获取某个集合中流行标签的数量。这是我希望执行的命令:

db.runCommand(
{ aggregate : "articles",
pipeline : [ { $unwind : "$Tags" },
{ $group : { _id : "$Tags", count : { $sum : 1 } }
} ]});

当我使用 shell 执行此操作时,我得到以下信息:

{
"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

关于c# - 使用 mongoDB C# 驱动程序,如何发出 runCommand?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10909063/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com