Details
-
Bug
-
Resolution: Done
-
Major - P3
-
None
-
2.6.5
-
None
-
ALL
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