Hi everyone hoping you all are fine. I am newbie using Mongoose NodeJS. What I want to push a new element in the nested array. However I dont know the index of matching document array. To push a new element in the matching document, the query I did is given below. However the query does not accepting outer and inner value and not updating the document.
var outer = 0;
var inner = 1;
vehicle.update({
ID: data[0],
"Trip.Name": data[1],
"Trip.Data.Time": data[2]
},
{
$push: {
"Trip.$[i].Data.$[j].Values": { $each: data[3] }
}
},
{
"arrayFilters": [{ i: outer }, { j: inner }]
},
function(err, result){
if(err){
console.log(err);
} else {
console.log(result);
}
})
Result:
{ ok: 0, n: 0, nModified: 0 }
It must push the new value in the array, because the values exists at Trip_Details.0.TripData.1.Values and If directly replace $[i] and $[j] with 0 and 1 then it update the document. But when I pass it as a variable then not modified.