0

I am trying to update an nested array using Array filters, for hands on first i am trying with basic array filter update query, i copied pasted the update query from the mongodb tutorial, But i am getting error like: Error:"No array filter found for identifier 'elem' in path 'grades.$[elem].mean' "and i am using 'db version v4.0.2' and 'MongoDB shell version v4.0.2

Here is my collection Details,

              {
              "_id" : 1,
              "grades" : [ 
              {
              "grade" : 80,
              "mean" : 75,
              "std" : 6
              }, 
              {
              "grade" : 85,
              "mean" : 90,
              "std" : 4
              }, 
              {
              "grade" : 85,
              "mean" : 85,
              "std" : 6
              }
              ]
              }
             //End of First Record
              {
              "_id" : 2,
              "grades" : [ 
               {
              "grade" : 90,
              "mean" : 75,
              "std" : 6
              }, 
              {
             "grade" : 87,
             "mean" : 90,
             "std" : 3
             }, 
             {
            "grade" : 85,
            "mean" : 85,
            "std" : 4
            }     
            ]
            }
            //End of Second record 

update Query:

          db.getCollection('students2').update(

         {   },
         { $set: { "grades.$[elem].mean" : 100 } },
         {
          multi: true,
          arrayFilters: [ { "elem.grade": { $gte: 85 } } ]
          }
          )

Throw's the Error: No array filter found for identifier 'elem' in path 'grades.$[elem].mean'

1 Answers1

0

Read the comments of this StackOverflow issue:

arrayFilters not working

It doesn't work in "older shells". I'm using the Robo 3T client and running into the same issue. The shell is apparently removing the arrayFilters object.

Jonathan Hensley
  • 131
  • 1
  • 1
  • 7