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

天蓬老师
天蓬老师

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

Antworte allen (1)
伊谢尔伦

如果你指的是fields的顺序有变化,那是因为JSON本身定义Object是一个fields的集合,是无序的。但是MongoDB主动地维护属性的顺序。

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.

那属性的顺序为什么会变呢,这是因为各个语言中对集合的实现不一样。比如python中的dict不维护顺序,所以他传到driver中的时候顺序已经变了,如果希望保持顺序,driver都提供了有序集合,比如python里的 SON.

    Neueste Downloads
    Mehr>
    Web-Effekte
    Quellcode der Website
    Website-Materialien
    Frontend-Vorlage
    Über uns Haftungsausschluss Sitemap
    Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!