title: Get only closest documents using mongodb geoNear or near
body: <p>I'm getting crazy to return closest Venues from a specific point using MongoDB. It is the first time I work on it so I'm totally new to this practice.</p>
  
  <p>What I did at the beginning is to create a 2DIndex of my Venue collection.</p>
  
  <p>Now I'm trying to get Venues in a range of 500 meters from a specific point and the code is this:</p>
  
  <pre class="lang-js prettyprint-override"><code>    Venue.find({ location:
          {
              $near: [ 52.3835443 , 4.8353073 ],
              $maxDistance: 0.5 / 6371
          }
      }, function (err, venues) {
          return venues;
      });
  </code></pre>
  
  <p>Unfortunately it return all documents.</p>
  
  <p>The Venue Model has the field for location like this:</p>
  
  <pre class="lang-js prettyprint-override"><code>"location": {
    "type": {
      "type": "string"
    },
    "coordinates": [{ "type": "Number" }]
  }
  </code></pre>
  
  <p>And all my Venues are like this:</p>
  
  <pre class="lang-js prettyprint-override"><code>{
   "name": "name",
   "address": "address",
   "location": {
    "type": "Point",
    "coordinates": [50.1981668, 7.9943994999]
   }
  }
  </code></pre>
  
  <p>I also tried using <code>$geoNear</code> but I always receive all documents and not only those in 500 meters distance.</p>
  
  <p>EDIT: </p>
  
  <p>Mongo version is 3.2;</p>
  
  <p>index:</p>
  
  <pre class="lang-js prettyprint-override"><code>{
      "v": 1,
      "key": {
          "location": "2dsphere"
      },
      "name": "location_2dsphere",
      "ns": "mydb.Venue",
      "2dsphereIndexVersion": 2
  }
  </code></pre>
  
  <p>document as wrote above:</p>
  
  <pre class="lang-js prettyprint-override"><code>{
   "name": "A name",
   "address": "An address",
   "location": {
    "type": "Point",
    "coordinates": [50.1981668, 7.9943994999]
   }
  }
  </code></pre>