MongoDB笔记十——空间索引
添加2D索引
db.map.ensureIndex({gis:"2d"},{min:-1,max:201})
默认或建立一个[-180,180]之间的2D索引
查询电(70,180)最近的3个点
db.map.find({gis:{$near:[70,180]}},{gis:1,_id:0}).limit(3)
![MongoDB笔记十——空间索引](https://app.yinxiang.com/shard/s22/res/78789306-3209-405d-8bb7-bcce55dabc70.png?resizeSmall&width=780)
查询一点(50,50)和点(190,190)为对角线的正方形中的所有点
db.map.find({gis:{$within:{$box:[[50,50],[190,190]]}}},{_id:0,gis:1})
![MongoDB笔记十——空间索引](https://app.yinxiang.com/shard/s22/res/995b62fb-b946-46c7-a203-f587001e588d.png?resizeSmall&width=780)
查询以圆心为(56,80),半径为50规则下的圆心面积中心的点
db.map.find({gis:{$within:{$center:[[]56,80],50]}}},{_id:0,gis:1})
![MongoDB笔记十——空间索引](https://app.yinxiang.com/shard/s22/res/6c56bf9c-0c67-472d-815e-d5750dd47c0e.png?resizeSmall&width=780)
网站栏目:MongoDB笔记十——空间索引
网页地址:http://azwzsj.com/article/ieegeh.html