Skip to content

Instantly share code, notes, and snippets.

@ayonliu
Created July 9, 2014 10:08
Show Gist options
  • Save ayonliu/6e34a7c4531b5d01c5b7 to your computer and use it in GitHub Desktop.
Save ayonliu/6e34a7c4531b5d01c5b7 to your computer and use it in GitHub Desktop.
Badvalue $geometry is required for geo near query

原因:需要为坐标建立索引, 坐标值要为 double 型。

db.places.ensureIndex({ "location": "2d" } )
'location'   => ['lng'=>42.241,'lat'=>55.5],
$mongo->db->places->find(
    'location'=>[
	'$geoWithin'=>['$centerSphere'=>[[floatval($lng), floatval($lat)], 1/3959]]
    ]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment