MongoDB: update only specific fields

后端 未结 4 1448
醉酒成梦
醉酒成梦 2021-01-11 12:22

I am trying to update a row in a (typed) MongoDB collection with the C# driver. When handling data of that particular collection of type MongoCollection

4条回答
  •  不思量自难忘°
    2021-01-11 13:08

    It´s possible to add more criterias in the Where-statement. Like this:

    var db = ReferenceTreeDb.Database;
    var packageCol = db.GetCollection("dotnetpackage");
    var filter = Builders.Filter.Where(_ => _.packageName == packageItem.PackageName.ToLower() && _.isLatestVersion);
    var update = Builders.Update.Set(_ => _.isLatestVersion, false);
    var options = new FindOneAndUpdateOptions();
    packageCol.FindOneAndUpdate(filter, update, options);
    

提交回复
热议问题