mongdb索引(6)

1.创建二维集合

{gis:{x:43,y:80}}

db.map.ensureIndex({gis:"2d"},{min:-1,max:201})

2.查询

db.map.find({gis:{$near:[70,180]}},{gis:1,_id:0}).limit(3)

3.查询以点(50,50)和点(190,190)为对角线的正方形中所有的点

db.map.find({gis:{"$within":{$box:[[50,50],[190,190]]}}},{_id:0,gis:1})

4.查询为(50,80)为圆心,半径微50的点

db.map.find({gis:{$within:{$center:[[56,80],50]}}},{_id:0,gis:1})

原文地址:https://www.cnblogs.com/youlangta/p/7354944.html