《mongoDB地理位置索引》要點(diǎn):
本文介紹了mongoDB地理位置索引,希望對(duì)您有用。如果有疑問,可以聯(lián)系我們。
相關(guān)主題:非關(guān)系型數(shù)據(jù)庫(kù)
將一些點(diǎn)的位置存儲(chǔ)在mongoDB中,創(chuàng)建索引后,可以依照位置來查找這些點(diǎn).
2d索引,用于存儲(chǔ)和查找平面上的點(diǎn) 平面地輿位置索引
2dsphere索引,用于存儲(chǔ)和查找球面上的點(diǎn). 球面地輿位置索引
db.location.ensureIndex({w:"2d"})
創(chuàng)建了地理位置索引,mongoDB不允許查詢跨越180的值
db.location.find({w:{$near:[1,1]}})
$near會(huì)返回最近的100個(gè)記錄.
db.location.find({w:{$near:[1,1],$minDistance:2,$maxDistance:10}})
限制最遠(yuǎn)距離:
限制最近距離:
最遠(yuǎn)和最近距離都限制:
由于$geoWithin是查詢某個(gè)形狀內(nèi)的點(diǎn),所以先要學(xué)會(huì)如何表現(xiàn)形狀.
db.location.find({w:{$geoWithin:{$box:[[0,0],[3,3]]}}})
db.location.find({w:{$geoWithin:{$box:[[1,1],[2,3]]}}})
db.location.find({w:{$geoWithin:{$center:[[0,0],5]}}})
db.location.find({w:{$geoWithin:{$polygon:[[0,0],[0,1],[2,5],[6,1]]}}})
db.runCommand({geoNear:"location",near:[1,2],maxDistance:10,num:1})
維易PHP培訓(xùn)學(xué)院每天發(fā)布《mongoDB地理位置索引》等實(shí)戰(zhàn)技能,PHP、MYSQL、LINUX、APP、JS,CSS全面培養(yǎng)人才。
轉(zhuǎn)載請(qǐng)注明本頁(yè)網(wǎng)址:
http://www.snjht.com/jiaocheng/10159.html