I want to prevent duplicate inserts of RecordLists, where two RecordsLists are the same if they have the same set of Records, i.e. the same array of sub-documents. This is the schema:
var RecordList = new Schema({
event: {type: ObjectId, ref: Event},
creator: {type: ObjectId, ref: User},
records: {
type: [Record],
unique: true }
}, {strict: true, safe: true})
But it seems that the unique: true in records doesn't work; when I save a RecordList with the same exact array of RecordSchemas as an existing one in the database, the duplicate is successfully saved, though I'd like it to return an error.
I'm new to Mongoose, and looking at other SO questions and the Mongoose documentation for a long time didn't turn up anything as far as I could tell. Sorry if this has an obvious answer!