I am trying to update an element at a specific index in a mongodb array with mongoose.
db.Comment.findOneAndUpdate(
{_id: '51fc9c329e87bf0000000001'},
{$set: { 'body.0' : 'Comment Body'}}).exec(...);
This works fine, however, when I use a variable to set the index it doesn't seem to work. Does anyone know why?
var indexString = "'body.0'";
db.Comment.findOneAndUpdate(
{_id: '51fc9c329e87bf0000000001'},
{$set: { indexString : 'Comment Body'}}).exec(...);
And how would I get this working so that I can set the index as needed?