There are two ways, and your mileage may differ from your best approach, but both are pretty terrible as MongoDB makes a βsensitiveβ match:
The first approach is to use $regex :
Profiles.findOne({ "username": { "$regex": "^" + newName + "\\b", "$options": "i" }})
This matches the word and only the exact word from the beginning of the line is case insensitive. The problem here is that you are scanning the index.
The second approach is to use an aggregate:
db.collection("profiles").aggregate([ { "$project": { "username": 1, "lower": { "$toLower": "$username" } }}, { "$match": { "username": newName }} ])
And you do it where, of course, newName already converted to lowercase.
The problem here is that there will be a $project across the pipeline. But it can be useful if you can $match .
Of course, I think that aggregate is only available on the server side, not through Minimongo, so this should be considered.
source share