I am trying to update the floor_num value from 1 to 9000 in an object in a nested array, in Mongoose:
thingSchema.findById(thingID, function(err, lm) {
if (!lm){
console.log(err);
}
else {
lm.update({'style.maps.localMapArray.map_marker_viewID': req.body.map_marker_viewID},
{'$set': {
'style.maps.localMapArray.$.floor_num': 9000,
}
}, function(err) {
//update success
});
}
});
But I'm getting this Mongo error:
MongoError: cannot use the part
(localMapArray of style.maps.localMapArray.map_marker_viewID) to traverse
the element ({localMapArray: [ { map_marker_viewID: "acympqswmkui",
floor_num: 1 } ]} code: 16837
My schema:
var thingSchema = new Schema({
style: {
maps: {
localMapArray: [{
map_marker_viewID : String,
floor_num : Number
}],
}
}
});
$(positional operator.) to update.