Is there a way to update a specific index in an array within a mongoDB document using a variable?
{
_id: 'IDString',
field: [ bla, bla, old, bla ];
}
let i = 2;
Collection.update(
{ _id: 'IDString' },
{ $set:
{ 'field.$.i': 'new' }
}
);
This should result in:
{
_id: 'IDString',
field: [ bla, bla, new, bla ];
}
I attempted to incorporate the variable i
, but my code did not produce the desired outcome.