Mongoose Schema - 在数组

时间:2016-05-31 12:49:13

标签: node.js mongodb mongoose

首先,抱歉我的英语。

大家好,我想创建一个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
      }
    }
  ]
});

0 个答案:

没有答案