Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-13933

compound index with numeric keys only

    • Type: Icon: Question Question
    • Resolution: Duplicate
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.4.4, 2.6.1
    • Component/s: Index Maintenance
    • None

      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"
              }
      ]
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            nefiga Ben Rotz
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: