lukejagodzinski / meteor-astronomy-validators

https://atmospherejs.com/jagi/astronomy-validators
MIT License
11 stars 13 forks source link

Unique validation should not bypass during updates #9

Open serkandurusoy opened 9 years ago

serkandurusoy commented 9 years ago

According to https://github.com/jagi/meteor-astronomy-validators/blob/master/lib/validators/comparison/unique.js#L11

you are checking for uniqueness only during inserts. But updates should also apply the validation rule.

Consider a case where I want usernames to be unique.

I insert user1 and user2 and then decide that I want to update user2 and want to set it to user1 which bypasses the unique check, hence misleading.

lukejagodzinski commented 9 years ago

Thanks I will fix it in the next release

serkandurusoy commented 9 years ago

While at it, could you also enhance the index definition so that we can create unique indexes?

lukejagodzinski commented 9 years ago

You already can create unique indexes by passing options. Read the documentation for Mongo Indexes. However I know that it should be something that is more easily accessible, so I will add unique option to definition of the field.

serkandurusoy commented 9 years ago

Oh, I was not aware that the unique option could be passed in the indexes.options object. Thanks!