I am looking at updating array objects in mongodb documents as below
var cursor = db.coll.find();
cursor.forEach(function(x){
if(x.arr) {
x.arr.forEach(function(y,i){
if(y.field1) {
db.coll.update({_id: x._id}, {$set:{'arr.'+i+'.field1': 'x' + y.field1}})
}
})
}
})
I get a syntax error at {$set:{'arr.'+i+'.field1': 'x' + y.field1}}
Is there a workaround?