I've asked a question couple of days ago about updating arrays in nested arrays of objects. Right now MongoDB 3.6 officially supports it via arrayFilters
feature.
Is it implemented in Mongoose 5.x.x? What's the syntax? Which method should I use?
Actually here is an example of findOneAndUpdate
command:
Company.findOneAndUpdate(
{'companyId': parseInt(req.params.companyId)},
{$pull: {'companyDivisions.$[element].divisionDepartments': {'departmentId': parseInt(req.params.departmentId)}}},
{arrayFilters: [{'element.divisionId': parseInt(req.params.divisionId)}]},
(err) => {
if (err) res.status(400).json(err)
res.status(200).json({success: true, message: 'this worked without errors!'})
}
)
I had two problems:
1) I tried to add a test
field which wasn't represented in my schema.
2) I completely forgot to parseInt
the hell out of my params, because in my schema these are numbers.
Thank you everybody. :D