[SERVER-11897] Mongodb compound 2dsphere index dosen't work as expected Created: 28/Nov/13 Updated: 10/Dec/14 Resolved: 01/May/14 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Geo, Index Maintenance |
| Affects Version/s: | 2.4.6 |
| Fix Version/s: | None |
| Type: | Question | Priority: | Major - P3 |
| Reporter: | Marco Biagi | Assignee: | Thomas Rueckstiess |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | 2dsphere, geo, geoIntersects, index | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Participants: | |||||||||
| Description |
|
I have a collection called search2 with about 20000 documents like this:
I define an index with this command:
On the collection there are only this index and the default index on "_id" field. When i execute the following query i expect "nscannedObjects" to be = 10 :
But this is the result:
If i remove sort from the query i obtain this:
So, why index is not used to sort results? From this documentation: http://docs.mongodb.org/manual/applications/geospatial-indexes/ http://docs.mongodb.org/manual/tutorial/sort-results-with-indexes/ I understand that MongoDb support "A compound index with scalar index fields (i.e. ascending or descending) as a prefix or suffix of the 2dsphere index field" and that "If the sort document is a subset of a compound index and starts from the beginning of the index, MongoDB can use the index to both retrieve and sort the query results." What am I missing? Thanks in advance |
| Comments |
| Comment by Thomas Rueckstiess [ 01/May/14 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi Marco, I noticed this ticket is still marked unresolved, apologies for that. As discussed in SERVER-10801, this was a limitation in the old query framework. I just wanted to let you know that I tested this issue with 2.6.0 and your particular use case seems to work now (see below). Therefore I'll mark this ticket as fixed. Regards,
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Marco Biagi [ 29/Nov/13 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Sorry, please change the version to 2.5.4. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Marco Biagi [ 28/Nov/13 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Note: in my collection i have 20010 object. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Marco Biagi [ 28/Nov/13 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I have made the same test with mongodb 2.5.4 and it dosen't seems to work as I Expect: The limit was 20. |