chris-l / mock-couch

A node.js module designed to mock a CouchDB server, mostly for unit testing purposes.
http://chris-l.github.io/mock-couch/
67 stars 44 forks source link

[#47] View collation does not sort keys correctly #48

Closed lucasyvas closed 10 months ago

lucasyvas commented 8 years ago

The function provided to R.sortBy causes a simple equality check to be performed on keys (a < b). The problem I discovered is that arrays are caught in the if (typeof k === 'object' && k !== null) check. This results in the comparison being done as a string instead of an array, which produces incorrect ordering.

It looks like Couch view collation applies key ordering implicitly (should not only be done if user provides starkey, endkey, descending, etc.). Therefore, it seems best to use keyCompare here in every case. This fixes the issue I was seeing with arrays, and presumably will fix any possible issues with other key type comparisons.

I would appreciate any feedback!