title: MongoDB $geoNear aggregation pipeline (using query option and using $match pipeline operation) giving different no of results
body: <p>I am using a $geoNear as the first step in the aggregation framework. I need to filter out the results based on "tag" field and it works fine but I see there are 2 ways both giving different results.</p>
  
  <p><strong>Sample MongoDB Document</strong></p>
  
  <pre>
  
      {
        "position": [
          40.80143,
          -73.96095
        ],
        "tag": "pizza"
      }
  
  </pre>
  
  <p>I have added 2dsphere index to the "position" key</p>
  
  <pre>
  
      db.restaurants.createIndex( { 'position' : "2dsphere" } )
  
  </pre>
  
  <p>
  <strong>Query 1</strong>
  <br /></p>
  
  <em><i><b>uses $match aggregration pipeline operation to filter out the results based on "tag" key</i></b></em>
  
  <pre>
  
      db.restaurants.aggregate(
        [
         {
             "$geoNear":{
  
                 "near": { type: "Point", coordinates: [ 55.8284,-4.207] },
                 "limit":100,
                 "maxDistance":10*1000,
                 "distanceField": "dist.calculated",
                 "includeLocs": "dist.location",
                 "distanceMultiplier":1/1000,
                 "spherical": true
          }
         },{
             "$match":{"tag":"pizza"}
         },
  
         {
            "$group":{"_id":null,"totalDocs":{"$sum":1}}
         }
        ]
      );
  
  </pre>
  
  <p><strong>Query 2</strong><br /></p>
  
  <em><b>Uses query inside the $geoNear aggregation operation to filter results based on "tag" key</em></b>
  
  <pre>
  
      db.restaurants.aggregate(
        [
         {
             "$geoNear":{
                 "query" : {"tag":"pizza"}
                 "near": { type: "Point", coordinates: [ 55.8284,-4.207] },
                 "limit":100,
                 "maxDistance":10*1000,
                 "distanceField": "dist.calculated",
                 "includeLocs": "dist.location",
                 "distanceMultiplier":1/1000,
                 "spherical": true
          }
         },
         {
            "$group":{"_id":null,"totalDocs":{"$sum":1}}
         }
        ]
      );
  
  </pre>
  
  <p>The grouping option is just to get the count of documents returned by both the queries.</p>
  
  <p>The totalDocs returned by both queries seem to be different.</p>
  
  <p>Can someone explain me the differences between both the queries ?</p>