Define a unique array of numbers in a mongoose Schema Define a unique array of numbers in a mongoose Schema mongoose mongoose

Define a unique array of numbers in a mongoose Schema


Ok, so in lieu of a better way, this is how I've solved it, using a save hook and an extra string:

var schema = new Schema({    array: { type: [Number], required: true }    _arraySignature: { type: String, unique: true }});schema.pre('save', function(next) {    this._arraySignature = this.array.join('.');    next();});

...but I can only do this because I know that my arrays will be sorted, never contain more than one of the same number, and immutable. It's a bit fugly. I'd love to know if there's a better way.