Vla*_*dak 8 c# mongodb mongodb-csharp-2.0 mongodb-.net-driver
如何通过使用IMongoCollection接口的新C#MongoDb驱动程序重写以下旧代码:
var bulk = dbCollection.InitializeUnorderedBulkOperation();
foreach (var profile in profiles)
{
bulk.Find(Query.EQ("_id",profile.ID)).Upsert().Update(Update.Set("isDeleted", true));
}
bulk.Execute();
Run Code Online (Sandbox Code Playgroud)
如何Update用Builder机制创建操作对我来说很清楚,但如何执行更新批量操作?
rno*_*nko 10
MongoDB.Driver有 UpdateManyAsync
var filter = Builders<Profile>.Filter.In(x => x.Id, profiles.Select(x => x.Id));
var update = Builders<Profile>.Update.Set(x => x.IsDeleted, true);
await collection.UpdateManyAsync(filter, update);
Run Code Online (Sandbox Code Playgroud)