Mongo schema, array of string with unique values
问题 I'm creating the schema for a mongo document and I can do everything except prevent duplicates in a non-object array. I'm aware of the addToSet, but I'm referring to Mongo Schema. I don't want to check on Update using $addToSet, rather I want this to be part of my schema validation. Example below. let sampleSchema = { name: { type: 'String', unique: true }, tags: [{ type: 'String', unique: true }] } The above snippet prevents name from having duplicate values. It allows tags to be stored as a