title: Mongo geolocation using $near and 2d index not being accurate
body: <p>I've written an application that finds local establishments and delivers them via a RESTful API. My stack is: express, express-resource and mongoose. Here is a sample of my model:</p>
  
  <pre><code>var PlaceSchema = new mongoose.Schema(
      {
          name: {
              type: String,
              required: true
          },
          geolocation: {
              lat: Number,
              lng: Number
          },
          address: {
              type: String
          }
      }
  );
  PlaceSchema.index({
      geolocation: '2d'
  });
  </code></pre>
  
  <p>I've checked a few times and my lon/lat values are being correctly stored in the db, so there aren't any data errors.</p>
  
  <p>Then I run the query to grab the data with the specific query values:</p>
  
  <pre><code>mongoose.connection.db.executeDbCommand(
      {
          geoNear: 'places',
          near: [
              parseFloat(req.body.lat),
              parseFloat(req.body.lng)
          ],
          num: limit,
          query: {
              // Some additional queries that
              // don't impact the geo results.
          },
          spherical: true,
          distanceMultiplier: 6371, // converting results to km
          maxDistance: distance / 6371,
      },
      function(err, result)
      {
          res.send(200, {
              status: true,
              data:   theaters
          });
      }
  );
  </code></pre>
  
  <p>There are a few issues with the results that it's returning: a) the calculation in km is <em>really</em> wrong. In most cases there's a 6-7km difference, but it varies, b) places that are closer are appearing farther than other places.</p>
  
  <p>I'm using the direct mongoose query because it will return the calculated distance (which I require for my API returns). Switching to the mongoose find method apparently wouldn't let me gain access to this data.</p>
  
  <p>Wondering if my index is perhaps wrong? Should it be 2dsphere instead? The documentation in that regard is slightly confusing, but most of the examples I see use just 2d.</p>
  
  <p>Thanks a bunch!</p>