0

my schema is like this

                {
                   _id : Default id,
                  "name" : "utk",
                   email : "kap@gmail.com",
                   scores: [
                     {examname : "english", score : 50},
                     {examname : "hindi" ,score : 59}
                         ]
                 }

i have to perform update on basis of email and examname of particular document lets say i have to update score to 90 where examname is equal to english and email is kap@gmail.com how can i do that i have tried this thing but doesn't work

             user.update({email : uemail,"scores.$[i].name": "fullstack" }, 
             {$set : {"scores.$[i].score" : scor}},function(err,result){
                 console.log(result+"in if");

                   });

i am trying to update it in app.put() method

learner
  • 1
  • 3
  • You're missing several options, and mostly the definition of `arrayFilters` required to match a positional filtered identifier for update. See the linked question for correct syntax and an example. Also "read it", because even with support for this it's still not a good idea to nest arrays. – Neil Lunn May 31 '18 at 03:59
  • Also your array is not actually "nested" in the sense of what we actually mean by that term. Simply using the [positional `$` operator](https://docs.mongodb.com/manual/reference/operator/update/positional/) is correct for this case. – Neil Lunn May 31 '18 at 04:05
  • Thanks it worked – learner May 31 '18 at 04:54

0 Answers0