title: Mongo/Mongoose check if an item exists
body: <p>I'm pretty new to building large-scale web applications with Mongo and Mongoose and I'm wondering what the correct way to check if an items exists is.</p>
  
  <p>I've commented the function below so it should be easy to understand what I'm doing and the wall I've hit. So essentially what I'm creating is: <code>item_exists ? do nothing : save</code>. I've currently removed the 'save' function as I'm not too sure where it should be placed.</p>
  
  <pre><code>app.post('/tracks/add/new', function (req, res) {
  
          var newTrack;
  
          // loop through the objects in req.body
          // item_exists ? do nothing : save
  
          for (var i = 0; i &lt; req.body.length; i++) {
  
              newTrack = new tracksTable({
                  for_user: req.user._id,
                  title: req.body[i].title,
                  artist: req.body[i].artist,
                  artwork: req.body[i].artwork,
                  source: req.body[i].source,
                  stream: req.body[i].stream
              });
  
              // check if the item already exists by
              // first finding the 'for_user' field and
              // any tracks associated with it (title)
  
              var query = tracksTable.find({});
  
              query
                  .where('for_user', req.user._id)
                  .select('title')
                  .exec(function (err, data) {
                      for (var x = 0; x &lt; data.length; x++) {
  
                          // this is where I've hit a wall...
                          // does 'this' track in the database match
                          // one in the request?
  
                      }
                  });
  
          }
  
      });
  </code></pre>