MongoDB field order and document position change after update

MongoDB allocates space for a new document based on a certain padding factor. If your update increases the size of the document beyond the size originally allocated the document will be moved to the end of the collection. The same concept applies to fields in a document.


FYI, in MongoDB 2.6 updates will preserve field order, with the following exceptions:

  1. The _id field is always the first field in the document.
  2. Updates that include renaming of field names may result in the reordering of fields in the document.

Tags:

Mongodb