I was trying to insert a name to my schema's "data_stream_map" array by finding using two parameters,
As follows,
var query = {
'_id': new ObjectId("594261a0ea2d89001c851424"),
'inputs.name': "name1"
};
return WFWorkflowModel.findOneAndUpdate(query, {$addToSet: {'inputs.$.data_stream_map': "121_name1"}}).then(function (result) {
return true;
}, function (error) {
console.error("WFEditor micro service - update dataStream.");
return error;
});
Nothing in the internet worked with me yet. But when it comes to Robomongo 0.9.0 this works,
db.getCollection('wfcomponents').findOneAndUpdate({
_id: ObjectId("594261a0ea2d89001c851424"),
'inputs.name': "name1"
}, {$addToSet: {'inputs.$.data_stream_map': "120_name1"}})
The mongoose document as follows,
{
"_id" : ObjectId("594261a0ea2d89001c851424"),
"key" : "task",
"description" : "",
"__v" : 0,
"updated" : ISODate("2017-06-12T07:08:58.462Z"),
"created" : ISODate("2017-06-12T07:08:44.079Z"),
"gridLocation" : {
"y" : 1,
"x" : 7
},
"inputs" : [
{
"name" : "name1",
"data_stream_map" : [
]
}
]
}
The used mongoose version is "mongoose": "^4.6.5", I'm out of clues, is there anyone can help me to overcome this issue? I refereed lots of stack overflow questions but its still unresolved.