why do i create an index before making geospatial query?

14 views
Skip to first unread message

aliane abdelouahab

unread,
Oct 2, 2012, 5:57:51 PM10/2/12
to mongodb-user
hi
my question seems to be dumb, because in "habit" we make queries and
try to making them faster by creating indexes, so why it's not the
case with geospatial indexing? is it because they're pair of values?

Stephen Steneker

unread,
Oct 3, 2012, 1:26:10 AM10/3/12
to mongod...@googlegroups.com
my question seems to be dumb, because in "habit" we make queries and
try to making them faster by creating indexes, so why it's not the
case with geospatial indexing? is it because they're pair of values?

Hi,

With a normal unindexed query, the query can still be satisfied by scanning the documents.  You can add an index later to improve the performance.

A geospatial query uses a 2d index, which encodes geohash codes on top of a MongoDB b-tree index.  You need to add the index first in order to have some geospatial context for your queries.

For some further reading on how the geospatial indexes work, see:

Cheers,
Stephen

aliane abdelouahab

unread,
Oct 3, 2012, 10:02:10 AM10/3/12
to mongodb-user
ah, now i get the idea
thank you :D
>  http://www.mongodb.org/display/DOCS/Geospatial+Indexing#GeospatialInd...
>  http://en.wikipedia.org/wiki/Geohash
>
> Cheers,
> Stephen
Reply all
Reply to author
Forward
0 new messages