Search code examples
mongodbsortingsails.jsmongodb-querysails-mongo

How to perform a sorting with case insensitive in the sails js framework?


model.find({city: city, sort: 'cityname ASC'}, function(err, cityList){});

the above code giving the correct sorting list but whenever the city is in both uppercase or lowercase like Coimbatore,bangalore,Chennai it gives the output as Chennai,Coimbatore,bangalore but i need the output as bangalore,Chennai, Coimbatore like that. Please help me to get the output as i wanted.. and advace thanking to you all..


Solution

  • This is an error in MongoDB - AFAIk there isn't really a solution for it as of now

    Update: A workaround I've found - store the strings a second time only upper or only lower case and sort by that property: http://futurestud.io/blog/case-insensitive-sorting-with-mongoose-and-mongodb/