title: Check if document exists in mongodb
body: <p>This is how I check if a document exists:</p>
  
  <pre><code>var query = {};
  
  if (req.body.id) {
      query._id = {
          $ne: new require('mongodb').ObjectID.createFromHexString(req.body.id)
      };
  }
  
  Creditor.native(function(err, collection) {
      collection.find({
          $or: [{
                  name: req.body.name
              }, {
                  sapId: req.body.sapId
              },
              query
          ]
      }).limit(-1).toArray(function(err, creditors) {
          if (creditors.length &gt; 0) {
              return res.send(JSON.stringify({
                  'message': 'creditor_exists'
              }), 409);
          } else {
              return next();
          }
      })
  });
  </code></pre>
  
  <p>To avoid that multiple documents exist with the same name or/and the same sapID I do this check on every creation/update of a document.</p>
  
  <p>E.g. I want to update this document and give it a different name</p>
  
  <pre><code>{
      name: 'Foo',
      sapId: 123456,
      id: '541ab60f07a955f447a315e4'
  }
  </code></pre>
  
  <p>But when I log the creditors variable I get this:</p>
  
  <pre><code>[{
      _id: 541a89a9bcf55f5a45c6b648,
      name: 'Bar',
      sapId: 3454345
  }]
  </code></pre>
  
  <p>But the query should only match the same sapID/name. However there totally not the same. Is my query wrong?</p>