【发布时间】:2011-11-10 21:15:28
【问题描述】:
The C# driver tutorial 为连接字符串提供以下格式(包括指定默认数据库的选项):
mongodb://[username:password@]hostname[:port][/[database][?options]]
但我没有看到不需要提供数据库名称的 GetDatabase 方法的重载。是否有其他方法可以获取表示连接字符串中指定的数据库的 MongoDatabase 实例?
【问题讨论】:
The C# driver tutorial 为连接字符串提供以下格式(包括指定默认数据库的选项):
mongodb://[username:password@]hostname[:port][/[database][?options]]
但我没有看到不需要提供数据库名称的 GetDatabase 方法的重载。是否有其他方法可以获取表示连接字符串中指定的数据库的 MongoDatabase 实例?
【问题讨论】:
这并没有超载。您可以改用这种方法:
var db = MongoDatabase.Create("mongodb://localhost:27017/SomeDatabase");
var collection = db.GetCollection("MyCollection");
【讨论】: