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
Post a Comment