首先,抱歉我的英语。
大家好,我想创建一个Schema来存储这样的数据:
var list1 = {
name: "Name of my list 1",
recipients: [
{
email: "email1@example.com",
name: "Name 1"
},
{
email: "email2@example.com",
name: "Name 2"
}
]
}
var list2 = {
name: "Name of my list 2",
recipients: [
{
email: "email2@example.com",
name: "Name 2"
},
{
email: "email3@example.com",
name: "Name 3"
}
]
}
但是,我希望obj.recipients.email
在对象中是唯一的,而不是在所有对象之间唯一。
我的猫鼬模式:
var ListSchema = new Schema({
name: String,
recipients: [
{
name: String,
email: {
type: String,
unique: true
}
}
]
});