How to do case insensitive DB search?


#1

I want to make a server-side method that will allow me to check if a user already exists in db.users, so I’ve made this:

Meteor.methods
  userExists: (username) ->
    check username, String

    console.log Meteor.users.find({username: username}).fetch()
    return { exists: true }

Obviously this is just a straight case-sensitive search. How do I look up a username regardless of case?


#2

Sheesh. Always right after I post! Typical. Here’s the solution:

    x = Meteor.users.find
      username:
        $regex: "^#{username}$", $options: 'i'
    console.log x.fetch()

#3

happens to me too all the time lols.