Mongoose: how to define a combination of fields to be unique? -


if had schema this:

var person = new schema({   firstname:  string,   lastname: string, }); 

i'd ensure there 1 document same firstname , lastname.

how can accomplish this?

you can define unique compound index using index call on schema:

person.index({ firstname: 1, lastname: 1}, { unique: true }); 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -