Lat-Long processing in mongoDB -


i using mongodb storing tweets of twitter using twitter apis , php code. how location of tweets stored in mongodb respect lattitude , longitude?

according twitter's documentation on tweet fields, coordinates field nullable geojson object. obviously, not tweets have coordinate data, you'll have account possibility.

conveniently, geojson format mongodb 2.4+ uses 2dsphere geospatial indexes. if you're storing tweet comes twitter, should able create such index on coordinates field , have mongodb track accordingly. if coordinates field null or not geojson object whatever reason, delete field document before storage, since mongodb complain if attempt index invalid geospatial value.

in earlier versions of mongodb, 2d indexes used, values either tuple of longitude , latitude values (in order), or object longitude , latitude properties (in order). recommend using newer 2dsphere indexes if possible.

a helpful chart of of mongodb's geospatial query operators can found on this page. includes mention of queries support 2dsphere , legacy 2d indexes.

two helpful blog posts introducing 2dsphere indexes are:

the latter post own, , talks using geojson php library wrote along doctrine mongodb. regardless of whether you'd explore using doctrine, geojson library may helpful validating coordinates fields before storing them in mongodb.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -