Mongoose geoNear returns weird distances

I'm using the mongoose driver in my node js application.

I tried using the geoNear function as follows:

Hike.geoNear( point, { spherical : true }, function(err, results, stats) { 
    if (err) {
        console.log(err);
        callback(false);
    } else {
        console.log('Here');
        console.log(results);
        callback(results);
    }
});

For some unknown reason, I get really short distances: 0.0009827867330778472
compared to the same query straight in mongo (without Mongoose): 6268.312062243817

Any idea why Mongoose changes the results?

It is returning the distance in radians, which you need to convert to a distance measurement based on the radius of the sphere.

The radius of the earth is 6371km (3959 miles). I've used this helper function in the past:

var theEarth = (function(){
  var earthRadius = 6371; // km, miles is 3959

  var getDistanceFromRads = function(rads) {
    return parseFloat(rads * earthRadius);
  };

  var getRadsFromDistance = function(distance) {
    return parseFloat(distance / earthRadius);
  };

  return {
    getDistanceFromRads : getDistanceFromRads,
    getRadsFromDistance : getRadsFromDistance
  };
})();

Given that you need to make the change for each result returned you'll probably want to loop through them and convert the distance at some point in the code. For example:

Hike.geoNear( point, { spherical : true }, function(err, results, stats) { 
  if (err) {
    console.log(err);
    callback(false);
  } else {
    console.log('Here');
    results.forEach(function(doc) {
      doc.distance: theEarth.getDistanceFromRads(doc.dis)
    });
    console.log(results);
    callback(results);
  }
});