[SERVER-16365] Compound index creation does not follow the order we specifiy Created: 01/Dec/14 Updated: 11/Jan/15 Resolved: 02/Dec/14 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | 2.6.0 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Arun Devaraj | Assignee: | Unassigned |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Operating System: | Windows | ||||||||
| Steps To Reproduce: | 1. Create a compound index- ) 2. After index is created, run collection1.stats() to look at the index created. |
||||||||
| Participants: | |||||||||
| Description |
|
When we create a compound index specifying a certain order of fields the order is reversed when the index is created. |
| Comments |
| Comment by J Rassi [ 02/Dec/14 ] | |||
|
This is a known issue with the mongo shell: the shell re-orders elements within documents that contain integers as field names. See I would advise that you modify your schema such that your documents do not contain integers as field names. Aside from this issue, you may also encounter unintuitive behavior when projecting subdocuments with these fields (see comment at SERVER-15013). As an alternative, you can work around this issue by creating the index using a MongoDB driver instead of the mongo shell. See PyMongo's create_index() function, as an example. | |||
| Comment by Arun Devaraj [ 02/Dec/14 ] | |||
|
Looks like I have an idea on what is happening. If the keys in a compound index have string and numeric values the order is reversed in the index. > use Rescore ) , , , | |||
| Comment by J Rassi [ 01/Dec/14 ] | |||
|
Please post the verbatim output of running the following at the mongo shell:
And, does the issue persist after restarting the shell? | |||
| Comment by Arun Devaraj [ 01/Dec/14 ] | |||
|
I am using the MongoDb shell for index creation. | |||
| Comment by J Rassi [ 01/Dec/14 ] | |||
|
Are you creating this index using the mongo shell, or are you using the ensureIndex() method from a MongoDB driver? If the latter, which driver are you using? |