mongoose - Delete element by id mongoose - Delete element by id mongoose mongoose

mongoose - Delete element by id


When you are using findOneAndRemove you need to wrap first parameter like this:

Property.findOneAndRemove({_id: req.params.propertyId}, req.body, function(err,data){    if(!err){        console.log("Deleted");    }});

If you try method findByIdAndRemove then you can call it like you did:

Property.findByIdAndRemove(req.params.propertyId,req.body, function(err,data){    if(!err){        console.log("Deleted");    }});

More information you can find in documentation.