mongoDB Geospatial Query $geoWithin got error 'Loop is not closed'

che*_*ara 3 geospatial mongodb mongodb-query

i am newbie for Geospatial Query of mongodb and i try search for point within polygon which have code like below :

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

and my data table look like below : 在此输入图像描述

i want to get result of all point is inside polygon.but i really have no clue

this error alway popup

|____/ Mongo 服务器错误 (MongoQueryException):查询失败,错误代码为 2,错误消息“循环未关闭:[ [ 104.9172382, 11.57934524 ], [ 104.9146632, 11.5724502 ], [ 104.92753788, 11.57976566 ] ]”在服务器上

感谢您的任何想法!

che*_*ara 10

我发现答案是我们需要开始坐标和结束坐标是相同的值。

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
            ]   
        ]
       }
     } 
   }
})
Run Code Online (Sandbox Code Playgroud)