【发布时间】:2018-04-25 09:32:11
【问题描述】:
我的架构是
var User = new mongoose.Schema({
//general information
name : {type:String},
email : {type : String},
number : {type : String},
password : {type:String},
//featured information
path: { type: String},
dob : {type:String},
gender : {type : String},
blood_group : {type:String},
marital_status : {type : String}
});
module.exports = mongoose.model('user',User);
我想用更新一些细节-
app.post('/contactinfo',function (req,res) {
var name = req.body.name;
var number = req.body.number;
var email = req.body.email;
User.update({_id : userID},{
$push : {
name : name,
number : number,
email : email
}
},{new : true },function (err,result) {
if(err){
console.log(err);
}
else{
console.log(result);
res.send({status : "success" , message : "Details updates"});
}
});
});
我没有在任何地方定义数组
但问题是更新时显示错误
{ MongoError: The field 'name' must be an array but is of type string in document {_id: ObjectId('5a0880e2d767e8131807e7f4')}
我被困在这里
请有人帮我解决这个错误
【问题讨论】:
-
如果我使用 $set 那么所有其他字段将被删除...
-
thnx ,它有效
标签: node.js mongodb mongoose schema