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(
)
db.testcol.find()
db.testcol.update(
{a:1},{$set:{c:22}})
db.testcol.find()
Case 2: Field size changes and the fields are reodered
db.testcol.find()
db.testcol.save(
)
db.testcol.find()
db.testcol.update(
{a:1},{$set:{c:"foobar"}})
db.testcol.find()
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(
)
> db.testcol.find()
> db.testcol.update(
{A:1},{$set:{C:"f"}})
> db.testcol.find()
- depends on
-
SERVER-6399 Refactor update() code
- Closed
- is duplicated by
-
SERVER-12412 Update an element in an array without changing internal order
- Closed
- is related to
-
SERVER-2991 Nice to have bson fields returned in determined order to making loading into data type / object faster.
- Open
- related to
-
SERVER-76705 Fields are reordered alphabetically by key when editing an existing document
- Closed