You can specify that the value of a field must be unique in a collection, meaning that no other documents can have the same value for that field. You do this by adding the unique
property to the Schema
object definition. For example, to add an index
and make the name
field unique
in the collection, you use:
var schema = new Schema({
name: {type: String, index: 1, unique: true}
};