认证登陆:
db.auth("yxg","yxg")
插入gps数据1
> db.address_info.insert( { loc : { type: "Point", coordinates: [ 121.466349,
31.2226834 ] }, name: "北海公园", category : "公园" } ))
插入gps数据2
78 ] }, name: "La Guardia Airport", category : "机场" } )
为gps数据做2dsphere索引
> db.address_info.ensureIndex( { loc : "2dsphere" } )查询 [120.261277, 30.317512] 的附近500的工具
> db.address_info.find( { loc : { $near : { $geometry : { type : "Point" , coord
inates : [120.261277, 30.317512] } , $maxDistance : 500} } })
本文介绍如何在MongoDB中使用地理空间索引进行数据插入及查询操作。通过具体的例子展示了认证登录过程、GPS数据的插入方法,并实现了2dsphere索引创建,最后演示了如何基于指定坐标进行附近的地点查询。


被折叠的 条评论
为什么被折叠?



