使用geoNear命令和地理空间索引来查找最近的MongoDB地区。下面是一个简单的示例:
db.places.createIndex( { loc : "2dsphere" } )
db.places.geoNear(
{ type: "Point", coordinates: [ , ] },
{ spherical: true }
)
其中
和
是经度和纬度的值,例如:
db.places.geoNear(
{ type: "Point", coordinates: [ -73.9667, 40.78 ] },
{ spherical: true }
)
这将返回按最接近的顺序排序的结果。
下一篇:按照镜像列值自定义行顺序