Step 11
To delete a user given their ID, you can use findByIdAndDelete
:
User.findByIdAndDelete("5f9a1d156e848f06c458f5f4")
.then((user) => console.log(user))
.catch((err) => console.log(err));
Before you run the above example, you must provide another "option" parameter to the connect
method:
const option = {
useNewUrlParser: true,
useUnifiedTopology: true,
+ useFindAndModify: false
};
Once you removed the user, try to find it using findById
method; it must return null
to you, indicating there is no user with the given ID.