Open petersimun opened 8 years ago
Let me make sure I'm understanding your request correctly. If you had a model, Person
, with unique-constrained fields firstName
and lastName
, you want to make sure that only one Person
document can have a given firstName
and lastName
? So there couldn't be two {firstName: 'Scott', lastName: 'Robinson'}
instances in the DB, correct?
exactly!
You can do it straightforward. Just set it in the schema, or the constructor. :)
how? can you provide me an example please?
It's in the docs. (README)
The default option supports both values and no-argument functions (like Date.now). Currently the supported options/validators are:
type: The value's type (required) default: The value to be assigned if none is provided (optional) min: The minimum value a Number can be (optional) max: The maximum value a Number can be (optional) choices: A list of possible values (optional) match: A regex string that should match the value (optional) validate: A 1-argument function that returns false if the value is invalid (optional) unique: A boolean value indicating if a 'unique' index should be set (optional) required: A boolean value indicating if a key value is required (optional)
i know it's possible to define in model that field is unique. Is it possible to do so over multiple columns/fields?
Thanks Peter