2dsphere index not used with $geoIntersects with multipolygon


I have a mongoDB collection with a compounds index as follows:

  1. someField: ascending
  2. loc: 2dsphere

For full disclosure, loc are polygons.

If I run a find query such as:
{someField: 'astringr', loc: {$geoIntersects: { $geometry: { type: 'Point', coordinates: [ -122.54, 37.71 ] }}}}
it works fine. However when I use a multipolygon such as:
{someField: 'astringr', loc: {$geoIntersects: { $geometry: {type:"MultiPolygon",coordinates:[[[[-146.3022,59.5739],[-146.5226,59.4288],[-146.2269,59.3426] .... (long list of polygons here)]]]}}}}
it also works, but is very slow.

Throwing this query in the query planner tells me that mongoDB is not using the 2dsphere index, but another index which only contains field someField with other indexed fields instead.

If I throw the first query (with a point rather than a multipolygon), then the query planner tells me the proper index is being used.

Why cannot mongoDB recognize the right index to use? Or are 2dsphere indexes unable to deal with (large) multipolygons? Is there a way around that?


Hi @Scarlett_Zuo ,

Can you share the getIndexes from this collection? What is the version of the 2dsphere index?

Additionally, try to clear cachePlan for this colleciton:

What is the MongoDB version? What is the driver used?