geoNear:函数(纬度,经度){ 返回新的Promise((resolve)=> { UserLocation.geoNear({类型:“点”,坐标:[parseFloat(query.lat),parseFloat(query.lon)]}}, {distanceField:“ dist.calculated”,maxDistance:100,球形:true),函数(错误,数据){ console.log('错误',错误); resolve((错误)?{}:(数据==空)?{}:数据) }) }) }
答案 0 :(得分:0)
让文档像
{
"_id" : 3,
"name" : "Polo Grounds",
"location": {
"type" : "Point",
"coordinates" : [ -73.9375, 40.8303 ]
}
}
您可以使用
进行查询db.collection.aggregate([
{
$geoNear: {
near: { type: "Point", coordinates: [ -73.98142 , 40.71782 ] },
key: "location",
distanceField: "dist.calculated"
}
}
])
有关更多详细信息,$geoNear