title: Finding a match in an array field
body: <p>In my image sharing application you can create albums and add images to them. When an image is deleted from the site, it should as well be removed from the album(s) that stores references to the image (name, id).</p>
  
  <p>The thing I need help with is to find which albums that has stored the image (reference) that's about to be removed.</p>
  
  <p>In the route below is what I've tried so far, but I get an error on the query. I've checked the Mongodb docs and the syntax looks like this:</p>
  
  <pre><code>db.collection.find( { field : { $in : array } } );
  </code></pre>
  
  <p>In my route the field and the array has switched places, which doesn't seem to work.</p>
  
  <p>I would really appreciate some help. Thanks in advance!</p>
  
  <p><strong>My models looks like the following:</strong></p>
  
  <pre><code>var AlbumSchema = new Schema({
        title             : String,
        imageName         : [String], &lt;-- array the contains of images names
        imageId           : [String] &lt;-- array the contains of images id's
  });
  
  modelObject.AlbumSchema = AlbumSchema;
  modelObject.Album = mongoose.model('Album', AlbumSchema);
  
  var ImageSchema = new Schema({
      name : String,
      size : Number,
      type : String
  });
  
  modelObject.ImgSchema = ImgSchema;
  modelObject.Image = mongoose.model('Image', ImgSchema);
  </code></pre>
  
  <p><strong>The route for deleting an image:</strong></p>
  
  <pre><code>app.get('/blog/delete/:id', function(req, res){
  
      model.ImagePost.findById(req.params.id, function (err, blog){
  
          var theImage = blog.name;
  
          if (err) {
              console.log(err);
              // do something
          }
  
          var query = albumModel.Album.find( { imageName: { $in : theImage } } );
  
          query.exec(function (err, albums) {
  
              if (!albums) {
                  console.log(err);
                  // do something
  
                  blog.remove(function(err) {
                      console.log(err);
                      // do something
                  });
  
                  res.redirect('/blogs');
              }
  
              else {
                  // code for removing the image(s) in the albums
  
                  res.redirect('/blogs');
              }
          });
      });
  });
  </code></pre>