MongoDb c#官方驱动批量更新

MongoDb c# official driver bulk update

如何通过使用 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();

我很清楚如何使用 Builder 机制创建 Update 操作,但如何执行批量更新操作?

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);

在新版本MongoDB.Driver上可以设置Flag

var query = Query<Profile>.In(p => p.ID, profiles.Select(x => x.Id));
var update = Update<Profile>.Set(p => p.IsDeleted, true);
Collection.Update(query, update, UpdateFlags.Multi);