标签:blog http io ar os sp java on div
初始化集合(经度在前,纬度在后)
|
1
2
3
|
mongos> db.checkins.insert({ "_id" : "101", "loc" : [ 116.3447, 39.9789 ]})mongos> db.checkins.insert({ "_id" : "102", "loc" : [ 116.3447, 39.8789 ]})mongos> db.checkins.insert({ "_id" : "103", "loc" : [ 116.3447, 39.5789 ]}) |
create geospatial index
|
1
|
mongos> db.checkins.ensureIndex({loc:"2d"}) |
查找44km以内的人
|
1
|
mongos> db.checkins.find({loc:{$near:[116.344722,39.9789],$maxDistance:44/111.12 }}) |
注意距离要除以111.2(1度=111.2km)
关于mongodb geospatial index 详见stackoverflow
标签:blog http io ar os sp java on div
原文地址:http://www.cnblogs.com/steven9801/p/4115119.html