【发布时间】:2016-10-14 18:00:17
【问题描述】:
我正在尝试更新我的记录,但在我的情况下没有发生,我不确定它出错的情况,任何人都可以建议我帮助。谢谢
我的猫鼬代码,
exports.updatestudent = function (req, res) {
var student = new Student(req.body);
var data = {};
var id = req.params;
var params = req.body;
var item = {
'name': params.name,
'rollnumber': params.rollnumber,
'class': params.class,
'city': params.city
};
Student.update({ _id: id },{ $set: item }, function (err, result) {
if (err) {
console.log('err');
}
if (result) {
data = { status: 'success', error_code: 0, result: result, message: 'Article updated successfully' };
res.json(data);
}
});
};
我的架构,
var StudentSchema = new Schema({
name: {
type: String
},
rollnumber: {
type: String
},
class: {
type: String
},
city: {
type: String
},
status: {
type: String
},
_id: {
type: Schema.ObjectId
}
});
/**
* Hook a pre validate method to test the local password
*/
mongoose.model('student', StudentSchema, 'student');
我在邮递员中的结果, { “状态”:“成功”, “错误代码”:0, “结果”: { “好”:0, “n”:0, “修改”:0 }, "message": "文章更新成功" }
我正在尝试更新我的记录,但在我的情况下没有发生,我不确定它出错的情况,任何人都可以建议我帮助。谢谢
【问题讨论】:
标签: node.js mongodb mongoose mongoose-schema