小编典典

名称类型的猫鼬字段

node.js

我正在尝试验证并保存具有以下结构的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”的属性,该属性保留用于猫鼬类型。我该如何解决?


阅读 219

收藏
2020-07-07

共1个答案

小编典典

您需要使用对象定义字段:

type: {type: String}
2020-07-07