Remove subdocument from array in MongoDB
JS
S
JavaScriptUse $pull to remove subdocuments
1 const [updatedSlotError, updatedSlot] = await SafeAwait(
2 SlotModel.update(
3 { _id: ObjectId(slot._id) },
4 {
5 $pull: {
6 'appointments.$[i].comments': { _id: commentId },
7 },
8 },
9 {
10 arrayFilters: [
11 {
12 'i._id': ObjectId(appointment._id),
13 },
14 ],
15 }
16 )
17 );Created on 12/2/2020