BsonValue and custom classes in MongoDB C# Driver

后端 未结 1 1795
独厮守ぢ
独厮守ぢ 2021-01-04 06:52

I\'m trying to use $push in an update query in mongodb, with the c# driver.

The Update.Push(...) method requires a string name (that\'s fin

1条回答
  •  北海茫月
    2021-01-04 07:49

    I know two approaches:

    1. Update.PushWrapped("arrayfield", myObjectInstance); //c# driver >= 1.0

    2. Or convert your class to BsonValue yourself via ToBsonDocument() extension method.

      Update.Push("arrayfield", myObjectInstance.ToBsonDocument());

    0 讨论(0)
提交回复
热议问题