0

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.

  • `arrayFilters` does not exist yet. It's only available from MongoDB 3.6, which is yet not released. – Neil Lunn Nov 02 '17 at 10:49
  • There are many users who are using arrayFilters in their queries, how they are doing this – user6542251 Nov 02 '17 at 10:55
  • Dude. Read the answer on the question you have been passed to **twice** now, and what has been clearly stated several times now. ***MongoDB 3.6***. You do NOT have this version, since it is not yet released. Do a `db.version()` from your shell. At best you have 3.4.9 because that is what is currently released. You either do not nest arrays at all ( recommended ) or follow the other methods. Or "wait". – Neil Lunn Nov 02 '17 at 10:59
  • @NeilLunn What are the other methods? – user6542251 Nov 02 '17 at 11:14

0 Answers0