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

The fields in a document are reordered (sorted alphabetically) when setting a field value

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 1.8.0-rc0
    • Fix Version/s: 2.5.2
    • Component/s: Write Ops
    • Labels:
      None
    • Environment:
      OS X. 1.8.0_rc0
    • Operating System:
      ALL

      Description

      The fields in a document are reordered when the size of the value stored in it changes (increases or decreases)

      Case 1: No change in size of field, so no change in field order
      db.testcol.find()
      db.testcol.save(

      {a:1,c:3,b:2}

      )
      db.testcol.find()

      { "_id" : ObjectId("4d5efc3bec5855af36834f5a"), "a" : 1, "c" : 3, "b" : 2 }

      db.testcol.update(

      {a:1}

      ,{$set:{c:22}})
      db.testcol.find()

      { "_id" : ObjectId("4d5efc3bec5855af36834f5a"), "a" : 1, "c" : 22, "b" : 2 }

      Case 2: Field size changes and the fields are reodered
      db.testcol.find()
      db.testcol.save(

      {a:1,c:"foo",b:2,d:4}

      )
      db.testcol.find()

      { "_id" : ObjectId("4d5efdceec5855af36834f5e"), "a" : 1, "c" : "foo", "b" : 2, "d" : 4 }

      db.testcol.update(

      {a:1}

      ,{$set:{c:"foobar"}})
      db.testcol.find()

      { "_id" : ObjectId("4d5efdceec5855af36834f5e"), "a" : 1, "b" : 2, "c" : "foobar", "d" : 4 }

      Case 3: Field size changes and the fields are reordered. Note : the _id field is moved to the last field on the node
      > db.testcol.find()
      > db.testcol.save(

      {A:1,C:"foo",B:2,D:4}

      )
      > db.testcol.find()

      { "_id" : ObjectId("4d5f16ceec5855af36834f60"), "A" : 1, "C" : "foo", "B" : 2, "D" : 4 }

      > db.testcol.update(

      {A:1}

      ,{$set:{C:"f"}})
      > db.testcol.find()

      { "A" : 1, "B" : 2, "C" : "f", "D" : 4, "_id" : ObjectId("4d5f16ceec5855af36834f60") }

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                7 Vote for this issue
                Watchers:
                12 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: