I save these documents in a MongoDB collection:
{ "_id" : ObjectId("5323850fa89de4a9f691dacf"), "name" : "B" }
{ "_id" : ObjectId("53238511a89de4a9f691dad0"), "name" : "a" }
{ "_id" : ObjectId("53238515a89de4a9f691dad1"), "name" : "A" }
{ "_id" : ObjectId("53238522a89de4a9f691dad2"), "name" : "z" }
{ "_id" : ObjectId("5323852ea89de4a9f691dad3"), "name" : "X" }
{ "_id" : ObjectId("5323855ea89de4a9f691dad4"), "name" : "á" }
Then I query sorting by name:
db.collection.find().sort({name:1});
and the result is:
{ "_id" : ObjectId("53238515a89de4a9f691dad1"), "name" : "A" }
{ "_id" : ObjectId("5323850fa89de4a9f691dacf"), "name" : "B" }
{ "_id" : ObjectId("5323852ea89de4a9f691dad3"), "name" : "X" }
{ "_id" : ObjectId("53238511a89de4a9f691dad0"), "name" : "a" }
{ "_id" : ObjectId("53238522a89de4a9f691dad2"), "name" : "z" }
{ "_id" : ObjectId("5323855ea89de4a9f691dad4"), "name" : "á" }
I have discovered that MongoDB not only doesn't support utf-8 sorting, but it also seems it doesn't support case insensitive sorting.
What is the best solution to support both types of sort?
(I am working with Mongoose and Express in a Node web application)