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 connection string like this;
mongodb://localhost/mydb
I would like to be able to db.GetCollection("mycollection") from mydb.
This would allow the database name to be configured easily in the app.config file.
Update:
MongoServer.Createis obsolete now (thanks to @aknuds1). Instead this use following code:It’s easy. You should first take database name from connection string and then get database by name. Complete example:
Important: If your database and auth database are different, you can add a authSource= query parameter to specify a different auth database. (thank you to @chrisdrobison)
From docs: