Open BusbyActual opened 6 years ago
The current version appears to support unique keys however not complex unique keys.
Example
const mongoose = require('mongoose'); const beautifyUnique = require('../scripts/mongoose-beautiful-unique-validation'); const Schema = mongoose.Schema; let modelSchema = new Schema({ name: { type: String, required: true, max: 100 }, serial: { type: String, required: true, max: 100 }, foreignKey: { type: String, required: true, max: 100 }, created: { type: Date, default: () => new Date() } }); modelSchema .index({ foreignKey: 1, serial: 1 }, { unique: true }); modelSchema .plugin(beautifyUnique); module.exports = mongoose.model('model', modelSchema );
Suggested
modelSchema .index({ foreignKey: 1, serial: 1 }, { unique: "'{VALUE}' is already in use" });
@BusbyActual Any update on this ? Custom message for compound indexes ?
The current version appears to support unique keys however not complex unique keys.
Example
Suggested