mongoDB 地理空间查询 $geoWithin 出现错误 'Loop is not closed'

标签 mongodb mongodb-query geospatial

我是 mongodb 地理空间查询的新手,我尝试在具有如下代码的多边形内搜索点:

db.properties.find({
  location:{
    $geoWithin : {
      $geometry : {
        type:"Polygon",
        coordinates: [[
            [104.9172382, 11.57934524],
            [104.9146632, 11.5724502],
            [104.92753788, 11.57976566]
        ]]
        } 
      } 
    }
  })

我的数据表如下所示: enter image description here

我想得到所有点都在多边形内的结果。但我真的不知道

这个错误总是弹出

|____/ Mongo Server error (MongoQueryException): Query failed with error code 2 and error message 'Loop is not closed: [ [ 104.9172382, 11.57934524 ], [ 104.9146632, 11.5724502 ], [ 104.92753788, 11.57976566 ] ]' on server

感谢任何想法!

最佳答案

我找到了答案,我们需要开始坐标和结束坐标是相同的值。

db.properties.find({
  location:{
    $geoWithin : {
      $geometry : {
        type:"Polygon",
        coordinates:[
            [
                [ 104.9212999921292 , 11.575955591122819 ] , // start loop
                [ 104.92129194550216 , 11.575198826419006 ] ,
                [ 104.92298978380859 , 11.575238241297862 ] ,
                [ 104.92291736416519 , 11.576023910057827 ] ,
                [ 104.9212999921292 , 11.575955591122819 ] // close loop
            ]   
        ]
       }
     } 
   }
})

关于mongoDB 地理空间查询 $geoWithin 出现错误 'Loop is not closed',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47665844/

相关文章:

c# - 用C#聚合$ lookup

java - MongoTemplate如何在查询中添加两个以上 "orOperator"

javascript - 使用 PHP 或 JS 将 BSON 检索到 MongoDB 镜像

javascript - 为什么找不到带有 '$all' 修饰符的文档?

arrays - 在 MongoDB 中查找包含专门包含特定文档的数组的文档

r - 根据另一个 sf 特征绘制 sf 对象的子集(对于某些状态)

mysql - MariaDB 没有 ST_Distance_Sphere 的等效函数

java - 或者同时使用 "like"和 "line break"和 "case insensitive"从 java 查询 mongodb

node.js - 如何正确删除 MongoDB 中的孤立引用?

google-app-engine - 我可以在 GAE 数据存储模型中拥有可选属性吗?