如何使用C#驱动程序在MongoDB中创建新数据库 [英] How to create a new database in MongoDB using the c# driver

查看:90
本文介绍了如何使用C#驱动程序在MongoDB中创建新数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了mongodb文档,似乎无法找到如何创建新数据库的方法.例如,在文档中说我可以像这样访问测试"数据库:

I have read through the mongodb documentation and cannot seem to find out how to create a new database. For example, in the documentation it says I can access the "test" database like this:

db.test.find()

现在,如果我想使用如下语法创建自己的数据库怎么办:

Now what if I want to create my own database using syntax like this:

db.MyDB.find()

还有什么我可以在线阅读的文档,我可以进一步阅读有关使用DOS接口和c#驱动程序创建数据库和集合的信息吗?

Also, is there any documentation I can read online I can further read about creating databases and collections using the DOS interface and the c# driver?

推荐答案

我可能是错的,但是埋在

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.

因此,C#行:

server.GetDatabase("myDB");

第一次调用它将创建一个名为myDB的新数据库.

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

从文档中:

GetDatabase 维护其具有的MongoDatabase实例的表 之前返回,因此如果您使用相同的名称再次调用 GetDatabase 参数,您将再次获得相同的实例.

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.

这篇关于如何使用C#驱动程序在MongoDB中创建新数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆