I want to store a load of arrays in mongoose on Node. I want to be sure those arrays contain a unique collection of numbers. Here's my Schema:
var schema = new Schema({
array: { type: [Number], unique: true, required: true }
});
It doesn't work. For example, creating and saving a couple of new db models that have a couple of (what I would call unique) arrays:
new Model({ array: [1,2] })
new Model({ array: [0,2] })
...causes this:
E11000 duplicate key error index: test2.modes.$array_1 dup key: { : 1 }
..so it looks like 'unique' is checking every index in those arrays for uniqueness, rather than the entire array as being unique.
Is there another way to do this in one step? Or do I have to perform a find on the db, say inside of a schema.pre('save', fn), to check the arrays are unique?