Categories
Mastering Development

Update Multiple Documents in MongoDb c# – whole entity not single value

I want to update a collection of documents in my collection, I don’t just want to update a field on the entity but rather the whole entity

public async void UpdateMany(IEnumerable<Car> cars)
{
    var filter = Builders<Car>.Filter.In(x => x.Id, cars.Select(x => x.Id));
    
    var update = Builders<Car>.Update.Set(x =< x, ??);
    var options = new UpdateOptions { IsUpsert = true };

    return await DbSet.UpdateManyAsync(filter, update, options);
}

Leave a Reply

Your email address will not be published. Required fields are marked *