[SERVER-13933] compound index with numeric keys only Created: 13/May/14 Updated: 10/Dec/14 Resolved: 02/Dec/14 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Index Maintenance |
| Affects Version/s: | 2.4.4, 2.6.1 |
| Fix Version/s: | None |
| Type: | Question | Priority: | Minor - P4 |
| Reporter: | Ben Rotz | Assignee: | Unassigned |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Participants: | |||||||||
| Description |
|
Is there a way to create a compound index in mongo with "numeric" keys? I imagine that mongo is sorting the object I pass it numerically after calling the ensureIndex function, which results in a compound key order of 1,2,3 instead of the desired 1,3,2. Thank you for any help you can provide
|
| Comments |
| Comment by Thomas Rueckstiess [ 15/May/14 ] | ||
|
Hi Ben, The issue appears to be how the shell converts documents with numeric key names. A quick test shows that the shell re-orders the fields before sending it to the server:
This is related to how arrays are stored as BSON. From the BSON spec page under "Notes":
I tested building an index on numeric keys from the Python driver, which uses a list to specify the key order, and that works without re-ordering the fields. I suspect other drivers will offer similar ways to preserve the order of index keys, so you should be able to create these indexes in correct order through a driver. Regards, |