C#MongoDB.Driver GetServer消失了,现在怎么办? [英] C# MongoDB.Driver GetServer is Gone, What Now?

查看:113
本文介绍了C#MongoDB.Driver GetServer消失了,现在怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自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屋!

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