我正在研究一种异步读取 json 文件(包含 json 对象数组)内容并将其插入 mongodb 集合的方法,但我无法弄清楚问题所在。调试的时候没有报错,但是我的收藏还是空的。
public async void InsertDocumentsInCollection(string File)
{
string text = System.IO.File.ReadAllText(File);
IEnumerable<BsonDocument> doc = BsonSerializer.Deserialize<BsonArray>(text).Select(p => p.AsBsonDocument);
//Name of the collection is Cars
var collection = _database.GetCollection<BsonDocument>("Cars");
await collection.InsertManyAsync(doc);
}