通过C#驱动执行mongodb shell脚本
我已阅读这个问题但不明白。是否能够通过 C# 驱动程序执行任意 mongodb shell 脚本?
I have read this question and haven't understand. Is there ability to execute arbitrary mongodb shell script via C# driver?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当您尝试更改属性类型时,这很有用,例如如下所示:
此代码更改
someProperty
的类型,它是集合的集合的元素:This is useful when you are trying to change property types for example like this:
This code changes type of
someProperty
which is element of a collection of a collection:不,您需要启动 Mongo shell 进程,使用类似 Process.Start,并传入要执行的命令,例如
C# 驱动程序 可以完成 shell 可以做的大部分事情,因此如果可能的话,直接使用驱动程序会更容易。
No, you'd need launch a Mongo shell process, using something like Process.Start, and pass in the command you want to execute, e.g.
However, the C# driver can do most things the shell can, so if possible it's much easier to use the driver directly.
我还没有尝试过,但我认为这就是您正在寻找的:
MongoServer.RunAdminCommand 方法(字符串)
http://api.mongodb.org/csharp/1.1/html/a83249ae-0989-7c24-7240-4506053d83c1.htm
I have not tried it but I think this is what you are looking for:
MongoServer.RunAdminCommand Method (String)
http://api.mongodb.org/csharp/1.1/html/a83249ae-0989-7c24-7240-4506053d83c1.htm