How to create a new database in MongoDB using the c# driver

家住魔仙堡 提交于 2019-12-01 16:55:50

I may be wrong, but buried in this documentation it looks like the call to GetDatabase on the server object will actually create the database if it has not already been created.

So, the C# line:

server.GetDatabase("myDB");

Will create a new database named myDB the first time it is called.


From the documentation:

GetDatabase maintains a table of MongoDatabase instances it has returned before, so if you call GetDatabase again with the same parameters you get the same instance back again.

There is no specific API/command required to create a DB in mongo. It creates it automatically when required. Read this article. to understand this in detail.

MongoDB driver has a feature where if a collection does not already exist then it automatically creates one. you can also use umongo an equivalent of Sql server management studio. This video explains a clear sample to start off with https://www.youtube.com/watch?v=6x0-vHHHpv8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!