If you are referring to the change in the order of fields, it is because JSON itself defines Object as a collection of fields, which is unordered. But MongoDB proactively maintains the order of attributes.
MongoDB preserves the order of the document fields following write operations except for the following cases:
The _id field is always the first field in the document.
Updates that include renaming of field names may result in the reordering of fields in the document.
Changed in version 2.6: Starting in version 2.6, MongoDB actively attempts to preserve the field order in a document. Before version 2.6, MongoDB did not actively preserve the order of the fields in a document.
Why does the order of attributes change? This is because the implementation of collections in each language is different. For example, dict in python does not maintain the order, so the order has changed when it is passed to the driver. If you want to maintain the order, the driver provides an ordered collection, such as SON in python.
If you are referring to the change in the order of fields, it is because JSON itself defines Object as a collection of fields, which is unordered. But MongoDB proactively maintains the order of attributes.
Why does the order of attributes change? This is because the implementation of collections in each language is different. For example, dict in python does not maintain the order, so the order has changed when it is passed to the driver. If you want to maintain the order, the driver provides an ordered collection, such as SON in python.