The structure of my document looks like this in MongoDB :-
{
_id : "7464bbuiecdhbjdje"
client : "MJMK"
users : [
{_id : "1234" , name : "first user"}
]
}
I would like to remove the whole document for matching users._id. In this case, for a user with _id 1234,the whole document needs to be removed. I have been unable to find any efficient function that does this in Node using mongoose. Thanks for your help.
Model.deleteOne({ 'users._id': "1234" })(whereModelis the variable representing your mongoose model )? Make sure that your_idhas the correct type as you defined in the schemausers? Is that a list of objects? Does each object have an_identry in it?