[SERVER-31620] Compound index with datetime and geospatial fields doesn't work Created: 18/Oct/17 Updated: 27/Oct/23 Resolved: 19/Oct/17 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Index Maintenance |
| Affects Version/s: | 3.4.9 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Michael Felix Dias | Assignee: | Mark Agarunov |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Operating System: | ALL | ||||||||
| Participants: | |||||||||
| Description |
|
I've created a compound index:
But when I run the query below the MongoDB doesn't consider the index, making a COLLSCAN.
Ps. When I create a compound index by datetime and another type of field it works (searching by index), as below:
I've seen in the documentation and I haven't found any reason for it. |
| Comments |
| Comment by Michael Felix Dias [ 20/Oct/17 ] |
|
So if I create a compound index with `sparse = false` it should works! Anyway I had already solved it as the same way that your recommendation. It makes me sure that I chose the best solution. Thanks! |
| Comment by Mark Agarunov [ 19/Oct/17 ] |
|
Hello michaelfdias, Thank you for the report. Looking over your examples, I believe this may be due to 2dsphere indexes being sparse. This behavior seems similar to the behavior described in
My recommendation would be to create another index for datetime which would be used for queries lacking a location field. Thanks, |