I’m trying to delete "627cfc7a9765ad8c65d03798" in ‘Rooms’
obje:
_id:627b93d43c14903de411d915
name:"Awesome Hotel Updated"
type:"hotel"
city:"berlin"
tittle:"Best Hotel in the City"
rooms:[
0:"627cf8c384aa07450d629279"
1:"627cfc7a9765ad8c65d03798"
]
function :
export const deleteRoom = async (req, res, next) => {
try {
await Room.findByIdAndDelete(req.params.id);
await Hotel.findByIdAndUpdate(req.params.hotelId, {
$pull: { rooms: req.params.id }
})
res.status(200).json("Room has been deleted.");
} catch (err) {
next(err)
}
}
Help me delete items in ‘Rooms’!
2
Answers
Probably you are looking for this:
Here in this "object" you should store your room id as above mentioned "room_id",
So this will help you to filter your rooms easy
Instead Try this:
The following code does work.
Maybe you’re getting an error somewhere inside the
findByIdAndUpdate
method