How can I update an array in a mongoDB document by index, which is stored in a variable?
{
_id: 'IDString',
field: [ bla, bla, old, bla ];
}
let i = 2;
Collection.update(
{ _id: 'IDString' },
{ $set:
{ 'field.$.i': 'new' }
}
);
So the result should be:
{
_id: 'IDString',
field: [ bla, bla, new, bla ];
}
My code wouldn't work, as I want to use the variable i.