Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>By definition the sort <strong>defaults to undefined</strong>, and so is the return order of documents. If there is no query then it will use the <a href="http://docs.mongodb.org/manual/reference/glossary/#term-natural-order" rel="noreferrer">natural order</a>. The results are returned in the <strong>order they are found</strong>, which may coincide with insertion order (but isn't guaranteed to be) or the order of the index(es) used.</p> <p>Some examples that will affect storage (natural) order:</p> <ul> <li>if documents are updated and don't fit in their currently allocated space, they will be moved</li> <li>new documents may be inserted in available gaps created by deleted or moved documents</li> </ul> <p>If an index is used, docs will be returned in the order they are found. If more than one index is used then the order depends internally on which index first identified the document during the de-duplication process.</p> <p>If you <strong>want a specific order</strong> then you <strong>must</strong> include a sort with your query.</p> <p>The exception noted for <a href="http://docs.mongodb.org/manual/core/capped-collections/" rel="noreferrer">capped collections' natural order</a> is because documents can't move and are stored in insertion order. The ordering is part of the capped collection feature that ensures the oldest documents "age out" first. Additionally, documents cannot be deleted or moved in a capped collection (see <a href="http://docs.mongodb.org/manual/core/capped-collections/#recommendations-and-restrictions" rel="noreferrer">Usage and Restrictions</a> for more info).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload