title: Will using $near with $maxDistance and $and act as a filter in MongoDB?
body: <p>So if we run a GeoSpatial MongdoDB query with a maxDistance like this:</p>
  
  <pre><code>db.getCollection('Places').aggregate([{
    "$geoNear": {
      "near": {
        "type": "Point",
        "coordinates": [-0.1251485, 51.5174914]
      },
      "spherical": true,
      "distanceField": "dist",
      "maxDistance": 2000,
      "query": {
        "field": "xxx"
      }
    }
  }
  }])
  </code></pre>
  
  <p>we get the following results as an Example:</p>
  
  <p><code>[PlaceA, PlaceB, PlaceC]</code></p>
  
  <p>Then, let's say we run the following query:</p>
  
  <pre><code>db.getCollection('Places').aggregate([{
      "$geoNear": {
        "near": {
          "type": "Point",
          "coordinates": [-0.1251485, 51.5174914]
        },
        "spherical": true,
        "distanceField": "dist",
        "maxDistance": 2000,
        "query": {
          "field": "xxx"
        }
      }
    },
    {
      $and: {
        name: {
          $eq: 'PlaceA'
        }
      },
    }
  ])
  </code></pre>
  
  <p>Assuming that we are trying to get <code>PlaceA</code> in this query.</p>
  
  <p>Correct if I am wrong, but doesn't MongoDB apply the geo query first and selects <code>PlaceA, PlaceB, PlaceC</code> and then filters out <code>PlaceB and PlaceC</code>. In other words, the <code>$and</code> is just acting as a filter and we can do the same filtering with a for loop rather than putting it in the MongoDB query:</p>
  
  <pre><code>for (eachPlace in Places) {
     if (eachPlace == 'PlaceA') {
       return eachPlace;
     }
  }
  </code></pre>