I am trying to alter the state of a property ("active") within an array of objects by setting it to either false or true based on which function I should invoke.
{
"_id": ObjectId("59fc98974aceec3e70a18715"),
"name": "Mostaganem",
"destinations": [
{
"active": true,
"seaport": ObjectId("59fc98594aceec3e70a18712")
},
{
"active": false,
"seaport": ObjectId("59fc98884aceec3e70a18714")
}
]
}
Although it works when executed in robo3T, the state change does not take effect when called through the API. Can you provide assistance?
async deactivate(id) {
/* await this.update(
{ destinations: { $elemMatch: { seaport: id } } },
{ $set: { 'destinations.$.active': false } },
{ multi: true }); */
await this.update({ '_id': id }, { $set: { 'destinations.$[].active': false } });
}
async deactivate(id) {
// await this.update({ destinations: { $elemMatch: { seaport: id } // }, { $set: { 'destinations.$.active': false } }, { multi: true });
await this.update({ '_id': id }, { $set: { 'destinations.$[].active': false } });
},