Skip to content

Case insensitive sort #867

@cristianfd

Description

@cristianfd

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions