【问题标题】:mongoose field with the name type名称类型为 mongoose 的字段
【发布时间】:2013-02-12 13:07:54
【问题描述】:

我正在尝试使用此结构验证和保存 Passport 配置文件:

http://passportjs.org/guide/profile/

这是我想出的方案:

// Define the schema.
schema = new mongoose.Schema({
    // The name of this user, suitable for display.
    displayName: String,
    // Each e-mail address ...
    emails: [{
        // ... with the actual email address ...
        value: String,
        // ... and the type of email address (home, work, etc.).
        type: String
    }],
    // A unique identifier for the user, as generated by the service provider.
    id: String,
    // The name ...
    name: {
        // ... with the family name of this user, or "last name" in most Western languages ...
        familyName: String,
        // ... with the given name of this user, or "first name" in most Western languages ...
        givenName: String,
        // ... and with the middle name of this user.
        middleName: String
    },
    // The provider which with the user authenticated.
    provider: String
});

电子邮件有一个名为“type”的属性,它是为猫鼬类型保留的。我该如何解决?

【问题讨论】:

    标签: node.js mongoose


    【解决方案1】:

    你需要使用一个对象来定义字段:

    type: {type: String}
    

    【讨论】:

    • 谢谢!当时间限制允许时,我会接受答案。一个不相关的问题,电子邮件数组现在有一个我不想要的 _id 字段。是否也有快速/简单的解决方法?
    • @RoelvanUden 查看这个问题的答案:stackoverflow.com/questions/12617754/…
    • 要禁用自动_id,只需将'_id:false'添加到对象:电子邮件:[{ _id:false,值:字符串,类型:{类型:字符串}}],
    猜你喜欢
    • 1970-01-01
    • 2021-08-26
    • 2016-11-27
    • 1970-01-01
    • 2021-04-27
    • 2019-01-01
    相关资源
    最近更新 更多