0

I am using mongoose in nodejs... I want to update deep array but cant update properly.. schema of this field is below...

case : [{
visit : [{
          visit_no : Number,
          treat : {
          rep : [{name : String,img :{type : String,match : /^http:\/\//i}}]
          }
}]}]

I had applied query with the help of https://jira.mongodb.org/browse/SERVER-831 is shown below...

update({"_id" : fields.id,"case._id" : fields.case,"case.visit._id" : fields.visit,"case.visit.treat.rep._id" : req.body.PInv},{$set : {"case.$0.visit.$1.treat.rep.$2.img" : req.body.img}})

But is will not showing error nor giving proper error.. i will require help for this problem

Santosh
  • 1
  • 1

1 Answers1

0

It could have something to do with mongoose not allowing you to use the $ operator more than once per key. Check out using the DocumentArray.id(id) method to search subdocuments. Check out Noam El's answer to this question. It might help you out to do a findById() on the outermost document before using the above method.

Hope this helps point you in the right direction!

Community
  • 1
  • 1