Why does meteor require unique emails?

Accounts.createUser fails when we test our application in staging because multiple users have the same email (typically the email of a hierarchical superior that will receive the “lost password” notifications)

This is understandable when you use your email as login, but for an application that uses unique logins I see no need to enforce this property. And sending the email to a manager is way better than sending it to a fake address or to the limbo…

I tried to update directly the emails array which is used by Accounts.sendResetPasswordEmail (userId) and the system refuses with the message

MongoError: E11000 duplicate key error index: StagingDB.users.$emails.address_1 dup key: { : "someemail" }e
=> Exited with code: 8

Do I have any other option than hacking the meteor source code ?

Yeah removing the mongodb index on startup, I wouldn’t recommend it though:


Perhaps if you add the same index again with unique: false after you removed it you won’t need to remove it everytime at startup, so give it a try! (I’m not sure)

Meteor.users._ensureIndex({"emails.address":1}, {unique:false});

Another, perhaps better option would be to save the email address in the user’s profile instead of using the builtin email functionality.

Also, you don’t NEED to supply an email on account creation, either a username or email is fine.

1 Like

In Accounts.createUser (options, callback), the name, password, email and profile are all optional

You cannot put the email address in the user’s profile because Accounts.sendResetPasswordEmail checks in user.emails[0].address. There is an optional email parameter but the documentation says it must be in the email list

Accounts.sendResetPasswordEmail(userId, [email])

userId String
The id of the user to send email to.

email String
Optional. Which address of the user’s to send the email to. This address must be in the user’s emails list. Defaults to the first email in the list.

This sounds like a one-off just for testing/staging? If that’s the case maybe look into handling this outside of Meteor at the mail sever level. You could look into setting something up like Gmail “+” email addresses. So:


All get sent to jsmith@gmail.com, but the email addresses appear to be unique when adding them via Accounts.createUser. I know this example is Gmail specific, but just about all email server software supports something similar.

Sadly the addresses are not on Gmail and we are testing pre-production with real data.

I think the Meteor accounts system treats the email as something you use to log in, rather than just a record of the email address. Perhaps there should be a way to do both.


Did you ever end up finding a solution to this? I am in the same boat (an application where multiple users will be using the default company email address, but for different accounts - i.e. Unique usernames).