Are arrays stored in MongoDB repositories?

The simple question is, do arrays keep their order when stored in MongoDB?

+62
mongodb
Jan 26 '12 at 4:23
source share
3 answers

yep MongoDB stores the order of the array .. just like Javascript engines ..

+62
Jan 26 2018-12-12T00:
source share

Yes, in fact, from a quick Google search on this issue, it seems rather difficult to reorder it: http://groups.google.com/group/mongodb-user/browse_thread/thread/1df1654889e664c1

+10
Jan 26 2018-12-12T00:
source share

I understand this is an old question, but Mongo docs now indicate that all the properties of the document keep their order as they are inserted . This naturally extends to arrays.

Document field order

MongoDB preserves the order of the document fields after write operations, except in the following cases:

  • The _id field is always the first field in the document.
  • Updates that include renaming field names can result in a reordering of fields in the document.

Changed in version 2.6: Starting from version 2.6, MongoDB is actively trying to maintain the order of the fields in the document. Prior to version 2.6, MongoDB did not actively maintain the order of fields in a document.

+3
Oct. 14 '14 at 18:47
source share



All Articles