Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Case insensitive sort #867

Open
cristianfd opened this issue May 29, 2018 · 0 comments
Open

Case insensitive sort #867

cristianfd opened this issue May 29, 2018 · 0 comments

Comments

@cristianfd
Copy link

cristianfd commented May 29, 2018

Create a collection with one string type property . Then insert a few data like the next example:

Bla
bla
Ala
ala

When you query with sort set to 1, for example:

http://localhost:2403/example/?_jsonquery={%22$sort%22:{%22title%22:1}}

The expected object would be:

Ala
ala
Bla
bla

But the returned object is:

Ala
Bla
ala
bla

This is a MongoDB problem but I found the solution without modifying the database collection. We need to add to the query a collation object with locale and strength, like the next example (extracted from here:

collection.find({ 'city' : 'New York' }, { '_id' : 0 }, { 'collation' : { 'locale' : 'en_US' , 'strength' : 2 }}).toArray(function(err, docs) {
      assert.equal(err, null);
      callback(docs);
  });

So, the solution is to insert the collation to the query, there was two alternatives:

  1. put the collation, for example, in the stripOptions function here
  2. allow to set the collation property in ctx.query

The first option is working for me, but I want to do a pull request and I`m sure that isn't the way. So I've started to implement the second solution but the collation property doesn't reach the db.js. I think there is a file that I haven't got in consideration between the get.js -> ?? -> db.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant