this is my schema:
var onlineStatusSchema = mongoose.Schema({
loc: {
type: {},
default:[]
}
});
onlineStatusSchema.index({loc:'2d'});
and this is my query:
var query = onlineStatus.find({
loc: {$nearSphere: [myLat,myLong], $maxDistance:10}});
query.exec(function (err,pros) {//response});
I am getting inaccurate data, i have tried changing 2d to 2dsphere also but it gives me all data which is within 10km or outside 10km
Try to divide the $maxDisatnce value with earth's radius ie, 6371
approx for KM.
$maxDistance:10/6371
This will help.