2dsphere vs 2d index performance 2dsphere vs 2d index performance mongodb mongodb

2dsphere vs 2d index performance


If you definitely don't need spherical geometry or more than one field in a compound geo index (see the notes on Geospatial Indexes in the MongoDB manual), a 2d index would be more appropriate. There will also be a slight storage advantage in saving coordinates as legacy pairs (longitude, latitude) rather than GeoJSON points. This probably isn't enough to significantly impact your write performance, but it depends what you mean by "lots of writes" and whether these will be pushing your I/O limits.

I'm not sure on the relative performance of queries for different geo index types, but you can easily set up a representative test case in your own dev/staging environment to compare. Make sure you average the measurements over a number of iterations so documents are loaded into memory and there is a fair comparison.

You may also want to consider a haystack index, which is designed to return results for 2d queries within a small area in combination with an additional field criteria (for example, "find restaurants near longitude, latitude"). If you are not fussed on accuracy or sorting by distance (and have an additional search field), this index type may work well for your use case.


2dsphere is now version 3 after MongoDB 3.2

2dsphere is better

data from https://jira.mongodb.org/browse/SERVER-18056

more details : https://www.mongodb.com/blog/post/geospatial-performance-improvements-in-mongodb-3-2

3.1.6 - 2dsphere V2

"executionTimeMillis" : 1875,

"totalKeysExamined" : 24335,

"totalDocsExamined" : 41848,

After reindex

3.1.6 - 2dsphere V3

"executionTimeMillis" : 94,

"totalKeysExamined" : 21676,

"totalDocsExamined" : 38176,

Compared to 2d

3.1.6 - 2d

"executionTimeMillis" : 359,

"totalKeysExamined" : 95671,

"totalDocsExamined" : 112968,