0
内部反对我得到了这个模式:节点和猫鼬 - 艾策斯另一个对象
var mongoose = require('mongoose');
var userSchema = new mongoose.Schema({
email: {type:String, unique: true, lowercase: true},
cpf: String,
password: String,
profile:{
name:{type:String, default:''},
photo: {type:String, default:''}
},
adress:String,
history:[{
date: Date,
paid:{type:Number, default:0},
item:{type:mongoose.Schema.Types.ObjectId, ref:'Products'}
}]
});
module.exports = mongoose.model('User', userSchema);
但是,当我使用User.create({电子邮件:req.body.email,密码:req.body.password, profile.name:req.body.name}),当我尝试传递一些值到profile.name时,控制台给我一个错误。 SyntaxError:意外的标记。
如何获取此对象并为他传递一些值?
谢谢,我亲爱的朋友。 –
但是,如果我尝试在EJS文件上使用它,会起作用吗?如:<%= result.profile.name%> –
是的。然后你访问数据(在这种情况下,这个人的名字)。这就像将值存储在代码的右侧。 – supersam654