Consider the following mongo data:
{ _id: "1",
names: ["John", "Peter"]
}
What is the correct way to replace a simple element in the array, getting the following result ?
{ _id: "1",
names: ["John", "Sarah"]
}
In my code I receive a function to exchange "Peter" with "Sarah", like:
substituteItemOnArray = (id, from, to) => {
MyModel.update({
id: id
},
{
??? What is the correct way to substitute one element with another ???
});
}
substituteItemOnArray("1", "Peter", "Sarah");