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

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]
        ]]
        } 
      } 
    }
  })

and my data table look like below : enter image description here

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

this error alway popup

|____/ 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

thank for any idea !



Solution 1:[1]

i found answer that we need to start coordinate and close coordinates are the same value.

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
            ]   
        ]
       }
     } 
   }
})

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 chea sotheara