使用c#驱动程序2.2.3关闭mongoDb服务器

栏目: C# · 发布时间: 7年前

内容简介:翻译自:https://stackoverflow.com/questions/35773305/shutdown-mongodb-server-with-c-sharp-driver-2-2-3

使用以前版本的C#驱动程序(1.x),我可以这样做:

var client = new MongoClient(settings);
var server = client.GetServer();
server.Shutdown();

如何使用驱动程序版本2.2.3执行此操作?

更新

那么我能找到的最好的是这样的:

try
{
    var client = new MongoClient(settings);
    var adminDatabase = client.GetDatabase("admin");
    var cmd = new BsonDocument("shutdown", 1);
    adminDatabase.RunCommand<BsonDocument>(cmd);
}
catch (MongoConnectionException e)
{
    if (!(e.InnerException is EndOfStreamException))
    {
        throw;
    }
}

但我真的不喜欢这个,Try / catch等……

他们在 Google Groups Page

告诉我,因为它绝不应该用于大多数应用程序.

Craig Wilson提到shutdown只是一个可以使用的命令

db.RunCommand("{shutdown: 1}")

因此,API .net 2.0.0及更高版本中不再提供它.

翻译自:https://stackoverflow.com/questions/35773305/shutdown-mongodb-server-with-c-sharp-driver-2-2-3


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Rapid Web Applications with TurboGears

Rapid Web Applications with TurboGears

Mark Ramm、Kevin Dangoor、Gigi Sayfan / Prentice Hall PTR / 2006-11-07 / USD 44.99

"Dear PHP, It's over between us. You can keep the kitchen sink, but I want my MVC. With TurboGears, I was able to shed the most heinous FileMaker Pro legacy 'solu-tion' imaginable. It has relationshi......一起来看看 《Rapid Web Applications with TurboGears》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具