Suppose you have the next class. It contains the systems in which the agent has worked
public class AgentHistory
{
public ObjectId Id { get; set; }
publi
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" }, { ... }, ... ]