Search code examples
ruby-on-railsindexingmongoidcase-insensitive

Case insensitive searching for words in mongoid


Is there a way to set an attribute in mongoid for case insensitive searches?

Lets say that somebody has a username: IAmGreat and I want to find the users data using their unique username without butchering it and changing it to iamgreat.

Thanks


Solution

  • Why not just down a User.login.downcase (or whatever your model/attribute combination is) when making the comparison? This will leave the capitalization in the DB as-is, but downcase the field just for comparison.