When calling createUser, accounts-password does a case insensitive query on the email address to check if its already taken (see here).
The query looks like this:
db.getCollection('users').find({
"$and": [
{
"$or": [
{
"emails.address": {
"$regex": "^mari",
"$options": ""
}
},
{
"emails.address": {
"$regex": "^marI",
"$options": ""
}
},
{
"emails.address": {
"$regex": "^maRi",
"$options": ""
}
},
{
"emails.address": {
"$regex": "^maRI",
"$options": ""
}
},
{
"emails.address": {
"$regex": "^mAri",
"$options": ""
}
},
{
"emails.address": {
"$regex": "^mArI",
"$options": ""
}
},
{
"emails.address": {
"$regex": "^mARi",
"$options": ""
}
},
{
"emails.address": {
"$regex": "^mARI",
"$options": ""
}
},
{
"emails.address": {
"$regex": "^Mari",
"$options": ""
}
},
{
"emails.address": {
"$regex": "^MarI",
"$options": ""
}
},
{
"emails.address": {
"$regex": "^MaRi",
"$options": ""
}
},
{
"emails.address": {
"$regex": "^MaRI",
"$options": ""
}
},
{
"emails.address": {
"$regex": "^MAri",
"$options": ""
}
},
{
"emails.address": {
"$regex": "^MArI",
"$options": ""
}
},
{
"emails.address": {
"$regex": "^MARi",
"$options": ""
}
},
{
"emails.address": {
"$regex": "^MARI",
"$options": ""
}
}
]
},
{
"emails.address": {
"$regex": "^mariXXXX@XXX\\.com$",
"$options": "i"
}
}
]
})
My app has about 400K users, and this query can take up to 6000ms (especially when the email address starts with a common first name).
My DB is hosted on Atlas, and of course has an index on the emails.address field.
Has anybody else experienced this? Am I missing something?