【发布时间】:2016-05-03 16:01:33
【问题描述】:
我有一个简单的 mogodb 数据库,我想使用 C# 显示文档的内容。到目前为止,我已经编写了以下代码:
var mongo_client = new MongoClient();
var mongo_database = mongo_client.GetDatabase("database_name");
var collection=mongo_database.GetCollection<BsonDocument>("collection_name");
using (var cursor = await collection.Find(new BsonDocument()).ToCursorAsync())
{
while (await cursor.MoveNextAsync())
{
foreach (var doc in cursor.Current)
{
Console.WriteLine(doc);
}
}
}
以上代码已被插入到异步方法中。连接已建立,但看起来它无法运行内部使用的代码。我在项目中添加了以下参考:MongoDB.Driver、MongoDB.Driver.Core 和 MongoDB.Bson。
指令Console.Writeline(doc); 没有显示任何内容,因为它没有被执行。但是为什么呢?
【问题讨论】:
标签: c# mongodb visual-studio-2015