Update Embedded document in mongodb using C#

陌路散爱 提交于 2019-12-01 23:43:38

You don't have to be so verbose: BsonValue.Create() and BsonArray.Create should not be required.

In fact, the latter is the cause of your problem: BsonArray.Create creates arrays of value types. You need an array of objects, however. If you take a look at the available overloads of BsonArray.Create, I guess you'll be invoking BsonArray.Create(IEnumerable), which is not desirable.

Have you tried to simply use

MongoCollection.Update(query, Update.Set("Agents", updatedEntity.Agents), ...);

instead?

In JSON, the difference looks like this:

Array of Values: [ val, val, ... ]

Array of Objects: [ { ... }, { ... }, ... ]

For example,

Simple Array: [ "mongodb", "awesomness", ... ]

Array of Objects: [ { userId: 2314234, comment: "Foo" }, { ... }, ... ]

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!