C#MongoDB.Driver GetServer消失了,现在怎么办? [英] C# MongoDB.Driver GetServer is Gone, What Now?
问题描述
来自mongoDB.Driver文档( http://docs.mongodb.org/ecosystem/tutorial/getting-started-with-csharp-driver/)
From the mongoDB.Driver docs (http://docs.mongodb.org/ecosystem/tutorial/getting-started-with-csharp-driver/)
获取对服务器对象的引用
要从客户端对象获取对服务器对象的引用,请编写以下代码:
To get a reference to a server object from the client object, write this:
var server = client.GetServer();
在最新版本中,GetServer
方法已消失,但是文档尚未更新,我们现在使用什么?
In the latest release the GetServer
method is gone, but the doc have not been updated, what do we use now?
感谢您的时间.
推荐答案
GetServer
是旧API的一部分.
GetServer
is part of the old API.
要使用新的,闪亮的和async
就绪的API,只需直接在客户端上调用GetDatabase
以获取IMongoDatabase
,并在其上GetCollection
以获得IMongoCollection
:
To use the new, shiny and async
-ready API simply call GetDatabase
directly on the client to get an IMongoDatabase
and GetCollection
on it to get an IMongoCollection
:
var db = client.GetDatabase("HamsterSchool");
var collection = db.GetCollection<Hamster>("Hamsters");
这篇关于C#MongoDB.Driver GetServer消失了,现在怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!