[英]C# MongoDB.Driver : How to see if server is connected. GetServer Replacement
[英]C# MongoDB.Driver GetServer is Gone, What Now?
來自mongoDB.Driver文檔( http://docs.mongodb.org/ecosystem/tutorial/getting-started-with-csharp-driver/ )
獲取對服務器對象的引用
要從客戶端對象獲取對服務器對象的引用,請寫下:
var server = client.GetServer();
在最新版本中, GetServer
方法已經消失,但文檔尚未更新,我們現在使用了什么?
謝謝你的時間。
GetServer
是舊API的一部分。
要使用新的,有光澤的和async
的API,只需在客戶端上直接調用GetDatabase
就可以獲取IMongoDatabase
和GetCollection
來獲取IMongoCollection
:
var db = client.GetDatabase("HamsterSchool");
var collection = db.GetCollection<Hamster>("Hamsters");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.