Details
-
Question
-
Resolution: Duplicate
-
Minor - P4
-
None
-
2.4.4, 2.6.1
-
None
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
> db.test.drop();
|
true
|
> db.test.ensureIndex({'1' : 1, '3' : 1, '2' : 1});
|
{
|
"createdCollectionAutomatically" : true,
|
"numIndexesBefore" : 1,
|
"numIndexesAfter" : 2,
|
"ok" : 1
|
}
|
> db.test.getIndexes();
|
[
|
{
|
"v" : 1,
|
"key" : {
|
"_id" : 1
|
},
|
"name" : "_id_",
|
"ns" : "test.test"
|
},
|
{
|
"v" : 1,
|
"key" : {
|
"1" : 1,
|
"2" : 1,
|
"3" : 1
|
},
|
"name" : "1_1_2_1_3_1",
|
"ns" : "test.test"
|
}
|
]
|
Attachments
Issue Links
- duplicates
-
MONGOSH-1037 Numeric field are sorted to the front (js shell)
-
- Closed
-