Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do arrays stored in MongoDB keep their order?

Tags:

mongodb

Simple question, do arrays keep their order when stored in MongoDB?

like image 937
Noah McIlraith Avatar asked Jan 26 '12 04:01

Noah McIlraith


People also ask

Does MongoDB guarantee order?

MongoDB only gurantee order of documents based on a sort operation. Therefore, even if some queries will return the order you need it won't be guaranteed for every query.

Are MongoDB documents ordered?

Documents are stored in natural order The documents are stored in descending order based on date. So the collection has 20140731 as the first document. Unless you are using a capped collection, there is no guarantee for the ordering of documents on disk (also referred to as natural order).


2 Answers

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

like image 118
dmb Avatar answered Sep 23 '22 01:09

dmb


Yes, in fact from a quick google search on the subject, it seems that it's rather difficult to re-order them: http://groups.google.com/group/mongodb-user/browse_thread/thread/1df1654889e664c1

like image 28
Chris Shain Avatar answered Sep 24 '22 01:09

Chris Shain