MongoDB Subdocument Update
JS
S
JavaScriptQuick guide for updating nested documents within MongoDB collections. Covers strategies and syntax for modifying subdocument fields efficiently.
1 await RaceModel.update(
2 { _id: slot._id },
3 {
4 $set: {
5 'appointments.$[i].status': computedStatus,
6 },
7 },
8 {
9 arrayFilters: [
10 {
11 'i._id': ObjectId(_id),
12 },
13 ],
14 }
15 );Created on 2/22/2021