0

So I had a model User with username and password fields. Later I changed it to use email instead of username. A similar change was made on another model - I renamed username to name. Both fields used unique validation from mongoose-unique-validator. Now, whenever I start the server, the mongoose created indexes for all fields, old and new. The first and the last things do not exist in the schemas anymore:

Mongoose: users.ensureIndex({ username: 1 }, { unique: true, background: true })
Mongoose: people.ensureIndex({ name: 1 }, { unique: true, background: true })
Mongoose: people.ensureIndex({ uri: 1 }, { unique: true, background: true })
Mongoose: people.ensureIndex({ username: 1 }, { unique: true, background: true })

Dropping database did not help, changing database did not help. I really do not understand where it might be coming from. Is there some sort of caching in mongoose?

Simoroshka
  • 339
  • 1
  • 7
  • 18

1 Answers1

0

Okay, the reason for this was the passport-local-mongoose that I was using incorrectly. It creates the indexes automatically. I needed to specify in the options, not just the local strategy, which fields I want to use for username and password. And for the second model it was just mistakenly plugged.

Simoroshka
  • 339
  • 1
  • 7
  • 18