Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usernameField not creating unique index #59

Open
eudaimos opened this issue Nov 9, 2014 · 3 comments
Open

usernameField not creating unique index #59

eudaimos opened this issue Nov 9, 2014 · 3 comments
Labels

Comments

@eudaimos
Copy link

eudaimos commented Nov 9, 2014

This may be a problem with the default username field as well, but since I'm using custom to set it to "email," I can't as yet validate the case.

When using mongoose.set('debug', true); I will see in the console:

Mongoose: accounts.ensureIndex({ _id: 1 }) { safe: undefined, background: true, unique: true }

What I expect to see is in the console is:

Mongoose: accounts.ensureIndex({ _id: 1 }) { safe: undefined, background: true, unique: true }
Mongoose: accounts.ensureIndex({ email: 1 }) { safe: undefined, background: true, unique: true }

Because a unique constraint index isn't created on accounts.email, my application allows

// directly in mongodb
db.account.update({ _id: 100 }, { $set: { email: "[email protected]" } })

// from mongoose where account is a document
account.update({ email: "[email protected]" }, function (uerr, numUpdated, raw) { ... });

to go completely unchecked, thus allowing 2+ users with the same username.

I am working around it by specifically defining email in my account schema like this:

...,
email: {
  type: String,
  required: true,
  lowercase: true,
  unique: true
},
...

... but I would expect this to be done already.

datagutt referenced this issue in Seriesbox/seriesbox-server Nov 23, 2014
@saintedlama
Copy link
Owner

Thanks for pointing that out I'll add the unique option as default true in the next version

@siboulet
Copy link

We also ended up with 2 accounts for the same user, apparently due to user double clicking the signup button. Manually added unique: true to our user field.

@saintedlama
Copy link
Owner

OK, this is something er need to fix.

@saintedlama saintedlama added the bug label Sep 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants