title: How to delete mongoose document and reference to it from another model?
body: <p>I have the following schemas:</p>
  
  <pre><code>const userSchema = new Schema({
    email: {
      type: String,
      unique: true,
      lowercase: true
    },
    password: String,
    favorites: [{ type: Schema.Types.ObjectId, ref: 'image' }]
  })
  
  const imageSchema = new Schema({
    description: String,
    title: String,
    url: String
  })
  </code></pre>
  
  <p>When I add an image I add a new image doc then I find the logged in user and update his favorites like so:</p>
  
  <pre><code>exports.addImage = function(req, res, next) {
    const email = req.user.email;
    imageData = req.body;
    imageData.url = req.body.media.m;
  
    const newImg = new Image(imageData);
    newImg.save()
      .then(function(image) {
        User.findOneAndUpdate(
          { email: email },
          { $push: { favorites: image._id } },
          function(err, doc) {
            if (err) { console.error(err) }
            res.status(201).send(doc)
          });
      });
  }
  </code></pre>
  
  <p>When I remove a favorite I would like to delete the image and update the user reference to the image. My code looks like this:</p>
  
  <pre><code>exports.deleteImageById = function(req, res, next) {
    const email = req.user.email;
    const id = req.body.id;
  
    Image.findOneAndRemove({ _id: id })
     .exec(function(err, removed) {
        User.findOneAndUpdate(
          { email: email },
          { $pull: { favorites: { _id: id } } },
          { new: true },
          function(err, removedFromUser) {
            if (err) { console.error(err) }
            res.status(200).send(removedFromUser)
          })
      })
  }
  </code></pre>
  
  <p>when I test it out, the image is deleted, but the user reference in favorites never updates to reflect the changes. What is going wrong here?</p>