c#MongoDB RunCommand

c#MongoDB RunCommand,c#,.net,mongodb,C#,.net,Mongodb,有人能给我举一个使用RunCommand方法的例子吗?它只接受MongoDB.NET驱动程序中可用的字符串参数(称为CommandName)?我知道有一个重载的RunCommand方法将对象引用(我认为是CommandDocument对象)作为参数,但我不想使用那个方法 我在获取CommandName的正确语法时遇到问题。提前谢谢 如果您使用的是官方C#driver的最新版本,那么您所指的基于“real”string的版本(CommandResult RunCommand(string comm

有人能给我举一个使用RunCommand方法的例子吗?它只接受MongoDB.NET驱动程序中可用的字符串参数(称为CommandName)?我知道有一个重载的RunCommand方法将对象引用(我认为是CommandDocument对象)作为参数,但我不想使用那个方法


我在获取CommandName的正确语法时遇到问题。提前谢谢

如果您使用的是官方C#driver的最新版本,那么您所指的基于“real”
string
的版本(
CommandResult RunCommand(string commandName)
)只是旧版驱动程序组件的一部分(请检查名称空间)。因此,我不建议使用它

“官方”界面当前如下所示:

TResult RunCommand<TResult>(Command<TResult> command, /* and some additional optional parameters */)
RunCommand<BsonDocument>("{count: \"collection_name\"}")
RunCommand<BsonDocument>(new BsonDocument("count", "collection_name"))