I'm using sails 0.11 and sails-mongo 0.11.2 adapter.
I have a user model with a nickname, and I want the nickname to be unique among every user. I specify the attribute as unique like this:
nickname: {
type: 'string',
unique: true
}
It is not working, I can add two users with the same nickname without a problem. Any clue on how to fix this issue?.
Okay I was struggling with this exact issue and resolved it. In config/locales/models.js change migrate : 'safe' to migrate : 'alter'. Lift your application. If there are any duplicates in your unique field it will error on lift, and you will have to delete the duplicates. After cleaning up any duplicates lift. Unique should now work. You can now change back to migrate : 'safe' and unique should continue to be enforced.