I've been at this problem for the whole day and I just can't seem to grasp what is the problem with $pull method in MongoDB, I am trying to remove an item from my shopping cart and I always get this:
WriteResult({ "nMatched" : 0, "nUpserted" : 0, "nModified" : 0 })
I want to remove item from my array 'products' in my schema with title of BTC
My 'carts' collection data in MongoDB:
{
"userId": {
"$oid": "5f940f8876ad3e073a2e1e8b"
},
"__v": 0,
"products": [{
"_id": {
"$oid": "5fc6888b1e10cd1b01382ec2"
},
"title": "BTC",
"price": 10000,
"amount": 6
}],
"totalPrice": 60000
}
My past 2 attempts:
db.carts.update({},
{ $pull: { "products": { title: 'BTC'} } } )
db.carts.update({ _id : '5fc6888b42d86bad7dafa319'},
{ $pull: { "products": { title: 'BTC'} } } )
Why don't I even get nMatched ?
use <db-name>