My Schema is like below:
const schema = new mongoose.Schema({
a: {
b: { type: String, unique: true },
c: { type: String }
},
aa: {
bb: [{
cc: { type: String, unique: true },
dd: { type: String }
}]
}
})
now I want to 'b' and 'cc' fields be unique. how can i do this?
I added this code at the end of the top code, but the schema allows duplicate values.
schema.index({'a.b':1}, {unique:true})
schema.index({'aa.bb.cc':1, {unique:true})
Do you have any idea to solve this problem?