Im trying to update nested array using arrayFilters, seems like it should work, according to documentation but I've got error:
Error parsing array filter: Expected a single top-level field name, found 'w' and 'd'
query looks like that:
db.getCollection("timesheets").update( {
"year": "2018",
"month": "06" }, {
"$set": {
"workers.$[w].days.$[d]": {
"day": 9,
"month": "06",
"year": "2018",
"isHoliday": false,
"isSaturday": true,
"isSunday": false,
"canEditPlanned": true
}
} }, {
"arrayFilters": [
{
"w._id": "XT5PFAPN9TFY3jXtJ",
"d.day": 9
}
] })
When using arrayFilters
to update a nested array, each nested level of the filter needs to be defined in its own element of the arrayFilters
array:
db.getCollection("timesheets").update({
"year": "2018",
"month": "06"
}, {
"$set": {
"workers.$[w].days.$[d]": {
"day": 9,
"month": "06",
"year": "2018",
"isHoliday": false,
"isSaturday": true,
"isSunday": false,
"canEditPlanned": true
}
}
}, {
"arrayFilters": [
{
"w._id": "XT5PFAPN9TFY3jXtJ"
},
{
"d.day": 9
}
]
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With