MongoDB学习之五----空间操作

本文介绍了MongoDB中如何使用geoJson格式存储点、线、面的几何信息,并详细阐述了包含查询$geoWithin、相交查询$geoIntersects、点查询$near以及周边查询geonear的操作方法,同时提到了建立2dsphere索引的重要性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

     MongoDB采用geoJson格式来存储常见的点,线,面的几何信息.

     点:db.points.insert({"pt":{type:"Point",coordinates:[10,10]}})

     线:db.lines.insert({"ln":{type:"LineString",coordinates:[[10,10],[20,20]]}})

     面:db.polygons.insert({"pg":{type:"Polygon",coordinates:[[[5,5],[5,15],[15,15],[15,5],[5,5]]]}})

    

     常见的空间查找操作:

     1.包含$geoWithin

        db.points.find({"pt":{$geoWithin:{$geometry:{type:"Polygon",coordinates:[[[5,5],[5,15],[15,15],[15,5],[5,5]]]}}}})  

        圆形查询:  db.points.find({"pt":{$geoWithin:{$centerSphere:[[6,6](圆心),2(半径)]}}) 

     2.相交$geoIntersects

         db.lines.find({"ln":{$geoIntersects:{$geometry:{type:"Polygon

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值