title: How to make Mongoose throw an error when pulling an entry via findByIdAndUpdate() does not find anything in the db?
body: <p>Hi I'm new to mongodb and node.js. I have the following abbreviated schema: </p>
  
  <pre><code>const PostSchema = new Schema({
    user: {
      type: Schema.Types.ObjectId,
      ref: 'user'
    },
    likes: [
      {
        user: {
          type: Schema.Types.ObjectId,
          ref: 'user'
        }
      }
    ],...
  </code></pre>
  
  <p>I want to access each Post by id (passed through request params) and then remove a like based on the user id. Presently, it removes the like from the array but does not then throw any errors when I try again to remove the same id from the db. Here is my code at the moment:</p>
  
  <pre><code>const like = await Post.findByIdAndUpdate(
        req.params.id,
        { $pull: { likes: { user: req.user.id } } },
        (error, result) =&gt; {
          if (!error) {
            return res.json('Post unliked');
          }
          return res.status(400).send('You have not liked this post');
        }
      );
  </code></pre>