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

python - jinja2: TemplateSyntaxError: expected token ',', got 'string' -

Qt4: how to send QString inside a struct via QSharedMemory -

node.js - NodeJS remote terminal to Dropbear OpenWRT-Server -