I'm using the following packages:
- MongoDB.Driver - Version="2.7.2"
- MongoDB.Driver.Core - Version="2.7.2"
My model looks something like this:
data: {
field1 :"1"
},
history: [{
field1 :"0"
}]
Now I want to create an update definition which takes the current object in "data" and inserts it into the "history" array.
I know how to do this with absolute values..:
var updateDef = Builders<Entity>.Update.Push(x => x.History, historyObject);
updateDef = updateDef.Set(x => x.Data, newDataModel);
The problem is that I want the "historyObject" to be automatically gotten from the current document's "data" field.
Any ideas?
Current workaround
To work around this problem I'm currently fetching the document first and using the data field from the result.
The problem with this is that if the data changes in the meantime we'll overwrite it with the .Set
operation without pushing it to the history array.