mongodb为什么同样的集合,两次插入的顺序会有变化呢?
天蓬老师
天蓬老师 2017-04-24 09:12:02
0
1
484

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(1)
伊谢尔伦

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:

  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.

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template