title: How does mongo retain order of an object when defining an index?
body: <p>From the mongodb docs</p>
  <p><a href="https://i.stack.imgur.com/0p79C.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0p79C.png" alt="The order of the fields listed in a compound index is important. The index will contain references to documents sorted first by the values of the item field and, within each value of the item field, sorted by values of the stock field. See Sort Order for more information." /></a></p>
  <p><a href="https://docs.mongodb.com/manual/core/index-compound/" rel="nofollow noreferrer">Docs link</a></p>
  <p>But in javascript you can't depend on the order of keys in an object . So how does mongo reliably preserve the order of <code>item</code> and <code>stock</code> in the above example of a compound index?</p>