Mongoose schema fields are reverse ordered in MongoDB Mongoose schema fields are reverse ordered in MongoDB mongoose mongoose

Mongoose schema fields are reverse ordered in MongoDB


Two things:

  • When you're working with objects in Javascript, you don't get guaranteed access order or persisted order like you might if you used something like an Array (or Map/Set/TypedArray etc.). So when you pass in that configuration object as a schema in Mongoose, my guess is that it doesn't convert it to some ordered array and probably keeps it in it's object form. To track down exactly how it goes about that, you'd need to look at the source, then the mongodb driver module, and then (if the answer still isn't there) maybe look into how MongoDB stores things and what sort of data structures it uses internally. I'm guessing order isn't guaranteed :)

  • RoboMongo is a GUI, so the way that it displays data isn't necessarily the same as the order of the data held by mongodb — it's likely that it's sorted for easier reading.

Does that help?