Using mongoose to query longitude and latitude distance, the returned data exceeds maxdistance?

  node.js, question

The code is as follows:

location:{type:[Number],index: '2d'},
 
 Shop.find({location:{$near:loc,$maxDistance: 5}}).limit(50).exec(function(err, doc) {
 if (err) {
 console.log(err);
 bracket
 
 callback(doc);
 });

Max distance: 5 represents the coordinates within the range of 5km from this longitude and latitude. among the returned results, there are values satisfying the conditions (less than 5km) but there are also values greater than 5km, and there are many more. may I ask what went wrong?

The complete code is as follows:

module.exports = function( mongoose) {
 var ShopSchema = new mongoose.Schema({
 shopName:     { type: String, unique: true },
 address:     { type: String},
 location:{type:[Number],index: '2d'},
 shopPicUrl:      {type: String},
 shopPicTrueUrl:{type: String},
 mark:  { type: String},
 open:{type:Boolean},
 shopType:{type:String},
 dish:   {type: [{
 dishName: { type: String},
 tags: { type: Array},
 price: { type: Number},
 intro: { type: String},
 dishPic:{ type: String},
 index:{type:Number}
 }]}
 
 });
 
 var Shop = mongoose.model('Shop', ShopSchema);
 
 var createShop = function(shopName, address,location, shopPicUrl, open,shopType,res, callback) {
 var shopInstance = new Shop({
 shopName: shopName,
 address: address,
 location: location,
 shopPicUrl: shopPicUrl,
 open:open,
 shopType:shopType
 //shopPicTrueUrl:shopPicTrueUrl
 });
 shopInstance.save(function(err){
 callback(err);
 });
 };
 return {
 createShop: createShop
 bracket
 bracket

https://docs.mongodb.com/manu …

To specify a point using legacy coordinates, $near requires a 2d index and has the following syntax:

bracket
$near: [ <x>, <y> ],
$maxDistance: <distance in radians>
bracket

The unit at this time is radian, so you need to convert the condition into radian unit when querying.