The simple question is, do arrays keep their order when stored in MongoDB?
yep MongoDB stores the order of the array .. just like Javascript engines ..
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
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 orderMongoDB 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.
MongoDB preserves the order of the document fields after write operations, except in the following cases:
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.