I've got a whole bunch of political boundaries defined in a MongoDB collection, which are (as you might guess) very complex polygons, with thousands of points.

One of the queries I need to run is to retrieve all the boundaries which overlap a rectangular map extent. Right now I'm just running a $geoIntersects query on the polygons, which are 2dsphere-indexed.

Since it's OK if the occasional polygon which doesn't actually overlap the map gets included by accident, I know I could just add a bounding-box property to each document which contains a simple rectangular boundary that includes the whole polygon, then index and run my $geoIntersects query against the boxes. But I'd prefer, if possible, to avoid having to add another property to the documents.

Is there a simpler/more efficient way to do this? Or is the bounding box idea the best option?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.