How to update and upsert multiple documents in MongoDB using C# Drivers

后端 未结 6 1881
清酒与你
清酒与你 2020-12-10 12:37

I am using MongoDB 2, and I want to update multiple documents and upsert a value like processed:true into the collection. But MongoDB c# api only allows us to

6条回答
  •  暖寄归人
    2020-12-10 13:32

    UpdateFlags is an enum in the C# driver that will let you specify both at once. Just like any other flags enum, you do this by bit "or"ing.

    var flags = UpdateFlags.Upsert | UpdateFlags.Multi;
    

    You can read the docs on enums here (http://msdn.microsoft.com/en-us/library/cc138362.aspx) paying special attention to the section on Enumeration Types as Bit Flags

提交回复
热议问题