Average update of the main MongoDb driver C #

How can I rewrite the following old code through the new C # MongoDb driver, which uses the IMongoCollection interface:

 var bulk = dbCollection.InitializeUnorderedBulkOperation(); foreach (var profile in profiles) { bulk.Find(Query.EQ("_id",profile.ID)).Upsert().Update(Update.Set("isDeleted", true)); } bulk.Execute(); 

How to create an Update operation with the Builder mechanism is clear to me, but how to perform a bulk update operation?

+7
c # mongodb mongodb-.net-driver
source share
1 answer

MongoDB.Driver has 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); 
+7
source share

All Articles