[SERVER-20994] 2dsphere index Created: 18/Oct/15  Updated: 18/Oct/15  Resolved: 18/Oct/15

Status: Closed
Project: Core Server
Component/s: Geo
Affects Version/s: 2.6.5
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Elyes Gherib Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Participants:

 Description   

Config. : single-node, unsharded, MongoDB v2.6.5 running on Mac OS X Yosemite.

I have a collection of about 240,000 documents. Each document contains many fields, and a "location" field which in turn always has two sub-fields: latitude and longitude. My backend needs to perform geospatial queries on the collection.

I thusly created a compound index with the fields declared in the following order:

  • location: "2dsphere"
  • all the other fields regardless of the order

This index works, but is not optimal, as the MongoDB staff told me during the Paris Mongo Days conference. I therefore changed the order of the fields, according to their advice. The order became:

  • equality fields
  • range fields
  • location: "2dsphere"

Furthermore, this page :
http://docs.mongodb.org/manual/tutorial/build-a-2dsphere-index/#create-a-compound-index-with-2dsphere-index-key

states the following regarding the 2dsphere index in MongoDB v2.6:
"Unlike the 2d index, a compound 2dsphere index does not require the location field to be the first field indexed."

However, when I changed the order of the index' fields and placed the location field in the last position, I get the following error message :

planner returned error: unable to find index for $geoNear query
at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:90)
at org.springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:1934)
at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:1817)
at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1628)
at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1611)
at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:535)
at org.springframework.data.mongodb.repository.query.AbstractMongoQuery$Execution.readCollection(AbstractMongoQuery.java:168)
at org.springframework.data.mongodb.repository.query.AbstractMongoQuery$CollectionExecution.execute(AbstractMongoQuery.java:191)
at org.springframework.data.mongodb.repository.query.AbstractMongoQuery.execute(AbstractMongoQuery.java:103)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:421)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:381)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy20.findNearEventWithCategoryV2(Unknown Source)
at com.XXXXXX.mongodbbenchmark.Main.run(Main.java:69)
at org.springframework.boot.SpringApplication.runCommandLineRunners(SpringApplication.java:677)
... 5 more



 Comments   
Comment by Elyes Gherib [ 18/Oct/15 ]

Duly noted.

Regards,
Elyes.

Comment by Ramon Fernandez Marina [ 18/Oct/15 ]

Thanks for the followup elyesgherib. Please note that the SERVER project is for reporting bugs or feature suggestions for the MongoDB server. For MongoDB-related support discussion please post on the mongodb-user group or Stack Overflow with the mongodb tag, where your question will reach a larger audience. A question like this involving more discussion would be best posted on the mongodb-user group. See also our Technical Support page for additional support resources.

Regards,
Ramón.

Comment by Elyes Gherib [ 18/Oct/15 ]

Please close this, it's my mistake.
I mistyped a field name in the index, and therefore the query planner couldn't choose the index that I created.

It works now.

Comment by Elyes Gherib [ 18/Oct/15 ]

Update: rebuilding the indexes or restarting the node doesn't fix the problem.

Comment by Ramon Fernandez Marina [ 18/Oct/15 ]

elyesgherib, can you please send the output of db.col.getIndexes() for this collection as well as the query you're running?

Thanks,
Ramón.

Generated at Thu Feb 08 03:55:55 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.