0
我知道我可能会听起来像你们一样,但总的来说,我是。 我想在c#中使用mongodb驱动程序。尝试做一些事情,比如添加一条记录。MongoDB C#使用新的驱动程序
今天我学到了所有基本的MongoDB查询,甚至用robomongo尝试过。
但我不明白如何在c#中使用它? 如何从主函数调用它?
这是我写的代码(尝试使用MongoDB的网站教程):
什么是等待?什么是任务?这是什么意思,以及如何使其工作?
非常感谢您的帮助。
class Program
{
protected static IMongoClient _client;
protected static IMongoDatabase _database;
public static void Main()
{
_client = new MongoClient();
_database = _client.GetDatabase("test");
Task simpleTask = Tasky();
}
public async Task Tasky()
{
var document = new BsonDocument
{
{ "address" , new BsonDocument
{
{ "street", "2 Avenue" },
{ "zipcode", "10075" },
{ "building", "1480" },
{ "coord", new BsonArray { 73.9557413, 40.7720266 } }
}
},
{ "borough", "Manhattan" },
{ "cuisine", "Italian" },
{ "grades", new BsonArray
{
new BsonDocument
{
{ "date", new DateTime(2014, 10, 1, 0, 0, 0, DateTimeKind.Utc) },
{ "grade", "A" },
{ "score", 11 }
},
new BsonDocument
{
{ "date", new DateTime(2014, 1, 6, 0, 0, 0, DateTimeKind.Utc) },
{ "grade", "B" },
{ "score", 17 }
}
}
},
{ "name", "Vella" },
{ "restaurant_id", "41704620" }
};
var collection = _database.GetCollection<BsonDocument>("restaurants");
await collection.InsertOneAsync(document);
}
}
???????????????????????????????????????? –