Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shutdown mongoDb server with c# driver 2.2.3

With previous version of C# drivers (1.x) I could do :

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

How can I do this with driver version 2.2.3 ?

Update

Well the best I could find is something like this :

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;
    }
}

but I dont really like this, the Try/catch etc ...

like image 832
lo pango Avatar asked Mar 03 '16 13:03

lo pango


1 Answers

They told me at the Google Groups Page that is because it should never be used from most applications.

Craig Wilson mentioned that shutdown is simply a command that can be send using

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

So it isn't anymore available in the API .net Version 2.0.0 and above.

like image 169
Smartis Avatar answered Oct 05 '22 00:10

Smartis