Spatial queries implementation in MongoDB

73 views
Skip to first unread message

anand...@gmail.com

unread,
Sep 2, 2014, 1:54:28 AM9/2/14
to mongod...@googlegroups.com
Hello All,

I'm trying to understand the internals of how the spatial indexing and querying works in MongoDB.

By doing some tracing, I found out how the 2dsphere index works for inserts and deletes - the S2AccessMethods's getKeys() is invoked to get the keys that cover the shape that are then inserted to the b-tree based index.

However, I am not able to find how querying works since getKeys() method doesn't seem to get invoked in any queries. I would have assumed that the getKeys() is useful to filter which all keys in the tree to consider for the query. 

Can a MongoDB expert point me to the right direction on where should I look? Thank you very much!

-Anand

Will Berkeley

unread,
Sep 4, 2014, 11:29:19 AM9/4/14
to mongod...@googlegroups.com
I think it'd be most profitable to start with a higher-level conceptual understanding of how geospatial querying works because things are sufficiently complicated conceptually that jumping into the details of code will obfuscate everything. There's a MongoDB blog post that explains the principles of spatial indexing and querying using the S2 library to generate coverings of regions on the surface of the Earth (and it has pictures!). I'm not familiar with the code so I don't have anything to contribute after that but I think the high-level understanding will be helpful in reading the specifics and may suffice for whatever purpose is drawing you to look into the internals.

-Will
Reply all
Reply to author
Forward
0 new messages