0

I am using php to query nearby places.

I have the following geoJSON in mongoDB

{
                "_id": {
                    "$oid": "dsfsdfsdfsdfsdfsdfsdf"
                },
                "type": "Feature",
                "geometry": {
                    "type": "Point",
                    "coordinates": [
                        125.6342343431232,
                        10.121543413333423
                    ]
                },
                "properties": {
                    "name": "Any Place"
                }
}

i want to query near by locations about a point, i have index in php as

$collection->ensureIndex(array("geometry" => "2dsphere"));  

and my query is:

$arr = $collection->find(array('geometry' =>array('near'=>array("geometry"=>array("type"=>"Point","coordinates"=>$longLat),'minDistance' => 1000,'maxDistance' => 5000 ) ), ));
var_dump($arr->explain());

$arr->explain() is not giving me the desired result. What's going wrong if someone can help.

Following is the result

array (size=15)
  'cursor' => string 'BasicCursor' (length=11)
  'isMultiKey' => boolean false
  'n' => int 0
  'nscannedObjects' => int 5
  'nscanned' => int 5
  'nscannedObjectsAllPlans' => int 5
  'nscannedAllPlans' => int 5
  'scanAndOrder' => boolean false
  'indexOnly' => boolean false
  'nYields' => int 0
  'nChunkSkips' => int 0
  'millis' => int 0
  'indexBounds' => 
    array (size=0)
      empty
  'allPlans' => 
    array (size=1)
      0 => 
        array (size=5)
          'cursor' => string 'BasicCursor' (length=11)
          'n' => int 0
          'nscannedObjects' => int 5
          'nscanned' => int 5
          'indexBounds' => 
            array (size=0)
              ...
  'server' => string 'h0043434.mongolab.com:43434' (length=26)

It is returning 'BasicCursor' , instead it should give 'S2Cursor'

user3691240
  • 45
  • 2
  • 7
  • Could you post the actual result, the explain and tell us what your desired result is? – wdberkeley Aug 26 '14 at 15:30
  • Here is the actual result – user3691240 Aug 27 '14 at 12:16
  • This works fine for me, testing in the mongo shell. Have you tried in the mongo shell to confirm there isn't something wrong with the php statements? I can't verify the correctness of php very well as I'm not that familiar with php. – wdberkeley Aug 27 '14 at 14:33
  • Found the ans to question myself. In php we need to match the exact json syntax i.e. $collection->find(array( 'geometry' =>array("\$near" =>array("\$geometry" => array('type'=>'Point','coordinates'=>array($long,$lat)),"\$minDistance"=>1000,"\$maxDistance" => 5000)))); i was missing the $ signs in php , and will be used as query above – user3691240 Aug 27 '14 at 14:53

0 Answers0