I have a document which looks like:
{
_id: 'random123',
days: [
{
_id: "1a",
day: "Monday",
tasks: ["shopping", "playing", "movie"]
},
{
_id: "1b",
day: "Tuesday",
tasks: ["office", "travel", "relax"]
},
]
}
Now I want to update "office" to "enjoy" in document of id "1b" of days array
I've tried achieving it using following code's
await Schema.updateOne({_id: ObjectId("random123")}, {$set: {"days.$[outer].$[inner]": "enjoy"}}, {arrayFilters: [{"outer._id": ObjectId("1b")}, {"inner.food": "office"}]})
This one code even throws an error
await Schema.updateOne({_id: ObjectId("random123")}, {$set: {"days.$[outer].tasks.$[inner]": "enjoy"}}, {arrayFilters: [{"outer._id": ObjectId("1b")}, {"inner.food": "office"}]})await Schema.updateOne({_id: ObjectId("random123"), days: {$elemMatch: {"_id": ObjectId("1b"), "tasks": "office"}}}, {$set: {"foods.$[outer].$[inner]": "enjoy"}}, {arrayFilters: [{"outer._id": ObjectId("1b")}, {"inner.food": "office"}]})
None of above code works; execpt 2nd, neither of them throws any error
I am unable to find any solution to this neither on stackoverflow nor on mongoDB official documentation