进入mongo目录执行./mongo 命令
-
#切换数据库
use coachlocdb.runCommand(
{
geoNear : "coachloc" ,
near : [113.9494700075728,22.5563142472829] ,
spherical : true ,
maxDistance: 10000/6378137,
distanceMultiplier: 6378137,
num:150
})#查找这个坐标附近10000米的150个最近的教练
返回如
{
"dis" : 4.990743785277491,
"obj" : {
"_id" : NumberLong(2944),
"_class" : "com.lili.location.dao.Po.CoachPo",
"loc" : [
113.949518,
22.556321
],
"dir" : -1,
"distance" : 0
}
}
#dis 标识距离4.99米如果需要详细过滤某个教练的距离
db.runCommand(
{
geoNear : "coachloc" ,
near : [113.9494700075728,22.5563142472829] ,
spherical : true ,
maxDistance: 10000/6378137,
distanceMultiplier: 6378137,
num:60,
query:{_id:1066}
})#就是id为1066的教练的数据返回
通过次方式去校验测试和实际运行场景时候遇到的问题