确保有loc:[longitude, latitude]属性
给loc增加索引AttractionSchema.index({loc: '2d'});
使用geoNear
db.places.find(
{
location: {
$nearSphere: {
$geometry: {
type : "Point",
coordinates : [ -73.9667, 40.78 ]
},
$minDistance: 1000,
$maxDistance: 5000,
}
}
}
)
spherical: true