mongodb - Setting value of an array element in Mongoose using index -


i trying update element @ specific index in mongodb array mongoose.

db.comment.findoneandupdate(     {_id: '51fc9c329e87bf0000000001'},     {$set: { 'body.0' : 'comment body'}}).exec(...); 

this works fine, however, when use variable set index doesn't seem work. know why?

    var indexstring = "'body.0'";      db.comment.findoneandupdate(         {_id: '51fc9c329e87bf0000000001'},         {$set: { indexstring : 'comment body'}}).exec(...); 

and how working can set index needed?

use object instead:

var myindex = { 'body.0' : 'comment body'}; var myindex1 = { 'body.1' : 'xxx'};  db.comment.findoneandupdate(     {_id: '51fc9c329e87bf0000000001'},     {$set: myindex}).exec(...);  db.comment.findoneandupdate(     {_id: '51fc9c329e87bf0000000001'},     {$set: myindex1}).exec(...); 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -