In my app, I have a User schema with a favorites key that stores an array of objects, each with a unique id. I am attempting to delete one of these objects based on its id. Here is the code snippet that I believe should accomplish this:
User.updateOne({id: req.user.id}, {$pull: {favorites: {id: req.params.id}}})
My expectation is that the above code will identify the user with the id equal to req.user.id and remove the object from the favorites array that has the id matching req.params.id. However, upon executing this code, I encounter no errors, yet the object doesn't get removed from the array.
I've explored various similar questions and attempted their solutions without success. There seems to be something crucial that I'm missing here. Any assistance would be greatly appreciated!