Wednesday, February 5, 2014

Geospatial Index in MongoDB

With MongoDB you can store Geospatial Information i.e. information about location in co-ordinates, longitude and latitude etc. MongoDB allows you to create indexes on Geospatial data.

MongoDB supports two type of Geospatial Index. But, MongoDB allows only one Geospatial Index per collection (table).

1.     2d Indexes
2.     2sphere Indexes

2d Indexes: When the data is stored as legacy coordinate pairs to support planar geometry in the fields, MongoDB allows to create 2d Indexes. To create a 2d sphere Index the syntax is following:

db.Collection_name.ensureIndex({location_field}: “2d”, additional_field: value}, {index-specification options})

2d Sphere Indexes: When the data is stored to support spherical geometry as longitude and latitude in the fields, MongoDB allows to create 2d Sphere Indexes. To create a 2d sphere Index the syntax is following:

Db.Collection_name.ensureIndex({location_field}: “2dsphere”})



Popular Posts

Blog Archive

Real Time Web Analytics