[英]Mongoose schema for array of objects and upon update objects should get added
var mongoose = require('mongoose');
module.exports = mongoose.model('GridModel', {
Request_Id : { type : Number, required : true },
viewStudents : { type : Array , default : [] }
});
The above one is the mongoose model and after update to the viewStudents fileds should get added. 上面是一个猫鼬模型,在更新到viewStudents文件之后应该添加。
Query for update is : 查询更新是:
var conditions = { Request_Id : req.body.Request_Id},
update = {
viewStudents : {
Student_Name:req.body.Student_Name,
Student_Id:req.body.Student_Id,
Resume:req.body.Resume}
},
options = { multi : true};
GridModel.update(conditions, update, options, callback);
function callback(err,res2) {
if(err)
res.send(err);
getGridRequests(res);
}
Final output after two updates should look like 两次更新后的最终输出应该是这样的
viewStudents: {
{
Student_Name: asa,
Student_Id : 3,
Resume : No
}
{
Student_Name: asfsdfa,
Student_Id : 34234,
Resume : No
}
}
But I am not getting the way I have shown with the above code 但是我没有按照上面的代码显示的方式
GridModel has no Request_Id
property. GridModel没有
Request_Id
属性。 Update should have $push
modificator: 更新应该有
$push
modificator:
{
viewStudents : {
$push: {
Student_Name:req.body.Student_Name,
Student_Id:req.body.Student_Id,
Resume:req.body.Resume
}
}
}
NOTE Upper camel case with underscores looks very strange to me. 注意带有下划线的上骆驼箱看起来很奇怪。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.