Node.js 名称类型为的mongoose字段
我正在尝试使用以下结构验证和保存Passport配置文件: 这就是我提出的方案:Node.js 名称类型为的mongoose字段,node.js,mongoose,Node.js,Mongoose,我正在尝试使用以下结构验证和保存Passport配置文件: 这就是我提出的方案: // 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 e
// 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}
谢谢如果时间允许,我会接受答案。一个不相关的问题,电子邮件数组现在有一个我不想要的_id字段。还有一个快速/简单的解决方法吗?@RoelvanUden看到了这个问题的答案:要禁用自动id,只需在对象中添加“id:false”:email:[{uID:false,value:String,type:{type:String}}],