node.js - 名称类型为 mongoose 的字段

标签 node.js mongoose

我正在尝试使用此结构验证和保存 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”的属性,它是为 Mongoose 类型保留的。我该如何解决?

最佳答案

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

type: {type: String}

关于node.js - 名称类型为 mongoose 的字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15100013/

相关文章:

javascript - 使用 Node 解析 XLSX 并创建 json

javascript - Jest 模拟特定的配置值

node.js - Mongoose .js : How can I update a deep embedded document by its id?

javascript - 当 `listener must be a function` 返回函数时,Node.js EventEmitter 函数错误 `typeof` - 可能是范围问题

javascript - 如何在 Node.js 中遍历 JSON 数组?

node.js - 在 Node.js 中使用 findAndModify 时出错

node.js - 使用 Mongo Migration 展平对象数据

MongoDB按ObjectIds数组聚合匹配

javascript - 是否可以更新 Mongoose 文档中的对象?

node.js - 使用 Gmail API Node.js 客户端发送大附件 (> 5 MB)