【发布时间】:2015-09-30 08:54:08
【问题描述】:
我想将文档保存在一个集合中,我的方法如下,但它根本不保存。
internal static void InitializeDb()
{
var db = GetConnection();
var collection = db.GetCollection<BsonDocument>("locations");
var locations = new List<BsonDocument>();
var json = JObject.Parse(File.ReadAllText(@"..\..\test_files\TestData.json"));
foreach (var d in json["locations"])
{
using (var jsonReader = new JsonReader(d.ToString()))
{
var context = BsonDeserializationContext.CreateRoot(jsonReader);
var document = collection.DocumentSerializer.Deserialize(context);
locations.Add(document);
}
}
collection.InsertManyAsync(locations);
}
如果我做了 async 和 await 然后它最近运行,我需要先运行它,然后只测试数据。
【问题讨论】:
-
您必须等待“InsertManyAsync”方法。