title: Aggregate match pipeline not equal to in MongoDB
body: <p>I am working on an aggregate pipeline for MongoDB, and I am trying to retrieve items where the user is not equal to a variable.</p>
  
  <p>For some reason, I couldn't make it work. I tried to use <code>$not</code>, <code>$ne</code> and <code>$nin</code> in different possible way but can't make it to work.</p>
  
  <p>This is how it looks like:</p>
  
  <p>Data sample:</p>
  
  <pre><code>[{
      "_id": { "$oid": "565674e2e4b030fba33d8fdc" },
      "user": { "$oid": "565674832b85ce78732b7529" }
  }, {
      "_id": { "$oid": "565674e2e4b030fba33d8fdc" },
      "user": { "$oid": "565674832b85ce78732b7529" }
  }, {
      "_id": { "$oid": "565674e2e4b030fba33d8fdc" },
      "user": { "$oid": "56f9dfc5cc03ec883f7675d0" }
  }]
  </code></pre>
  
  <p>Pipeline sample (simplified for this question):</p>
  
  <p>Where <code>req.query.user.id = "565674832b85ce78732b7529"</code></p>
  
  <pre><code>collection.aggregate([
      {
          $match: {
              user: {
                  $nin: [ req.query.user.id ],
              }
          }
      }
  ]
  </code></pre>
  
  <p>This should return only the last item.</p>
  
  <p>Do you have any idea how to retrieve the data that doesn't match the user?</p>
  
  <p>Thanks</p>
  
  <p><strong>Edit:</strong> 
  The following doesn't work either:</p>
  
  <pre><code>collection.aggregate([
      {
          $match: {
              'user.$oid': {
                  $nin: [ req.query.user.id ],
              }
          }
      }
  ]);
  </code></pre>
  
  <p>I also tried with <code>ObjectID()</code> and mongodb complains: <code>[MongoError: Argument must be a string]</code></p>
  
  <pre><code>var ObjectID = require('mongodb').ObjectID;
  
  // Waterline syntax here
  MyCollection.native(function (err, collection) {
      collection.aggregate([
          {
              $match: {
                  'user': {
                      $nin: [ ObjectID(req.query.user.id) ],
                  }
              }
          }
      ], function (err, result) {
          console.log(err, result);
      });
  });
  </code></pre>
  
  <p>But this line works in the shell:</p>
  
  <pre><code>db.collection.aggregate([{$match:{"user":{"$nin":[ObjectId("565674832b85ce78732b7529")]}}}])
  </code></pre>