SoftInstigate / restheart

Rapid API Development with MongoDB
https://restheart.org
GNU Affero General Public License v3.0
807 stars 171 forks source link

The keys are sorted alphabetical with mongodb 3.6 #283

Closed kpetros closed 6 years ago

kpetros commented 6 years ago

I'm using restheart 3.2.2 and mongodb 3.6 When i insert a document, the keys are reordered (alphabetical order). I was using Mongodb 3.4 with restheart and the order was preserved.

mkjsix commented 6 years ago

Hi @kpetros, RESTHeart should not behave differently with different MongoDB versions, so it looks like this is a new feature in MongodB 3.6. I have not tested this directly but I have found the following article:

The most significant behavior change from an application perspective is sorting on arrays in find and aggregate queries. It is important to review this new behavior in a test environment when upgrading to MongoDB 3.6, especially if the exact order of sorted arrays in find results is crucial.

In MongoDB 3.6 sorting, a sort field containing an array is ordered with the lowest-valued element of the array first for ascending sorts and the highest-valued element of the array first for descending sorts. Before 3.6, it used the lowest-valued array element that matches the query.

Ref: https://www.percona.com/blog/2017/12/22/mongodb-3-6-sorting-changes-useful-new-features/

Not sure if this is what you are experiencing.

kpetros commented 6 years ago

Hi @mkjsix , I'm talking about keys reorder , not array elements. For example, this document

{ "B":"value", "A" : "value"}

will end up like this

{ "A":"value", "B" : "value"}

I have tested it directly to the database and this does not happen.

mkjsix commented 6 years ago

Sorry for the very late reply, but we haven't gathered any other similar feedback so far. We should run a test against mongo 3.6 and mongo < 3.6 to compare the results. @kpetros could you provide us with any test?