How to get the Mongo database specified in connection string in C#

前端 未结 4 2176
难免孤独
难免孤独 2020-12-29 19:37

I would like to connect to the database specified in the connection string, without specifying it again in GetDatabase.

For example, if I have a connec

4条回答
  •  心在旅途
    2020-12-29 19:58

    The answer below is apparently obsolete now, but works with older drivers. See comments.

    If you have the connection string you could also use MongoDatabase directly:

    var db =  MongoDatabase.Create(connectionString);
    var coll = db.GetCollection("MyCollection");
    

提交回复
热议问题