'mongodb remove array from the collection using index or any method
I have the following collection :
I use the following code to remove the element of the orderList array that matches the orderId. But it doesn't work.
Order.update({"_id":ObjectId(userOrder._id)},{"$pull":{"orderList":{orderId: "WPN-1645691337205"}}});
and I tried the following code as well
Order.update({"_id:":ObjectId("621741dcd40da387489093c2")}, {$unset : {"orderList.0" : 1 }});
Order.update({"_id:":ObjectId("621741dcd40da387489093c2")}, {$pull:{"orderList":null}});
Thanks, Jo
Solution 1:[1]
Try this:
Order.update(
{ _id: ObjectId(userOrder._id)},
{ $pull: { orderList: { orderId: "WPN-1645691337205" } } },
function(error, response) {}
);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Aimsat |

