对于与mongosee一起使用的GET
和findOne()
查询,我有非常类似的溃败,但PUT和updateOne()却没有。为什么?
路线
router.put("/user/:id", (req, res, next) => {
userService.updateOne(String(req.params.id), {$set: req.body[0]}, (err, data) => {
if (!err) {
console.log(req.params.id);
console.log(req.body[0]);
console.log("we must be in mongoose!")
res.json(res.data);
} else {
console.log(Number(req.params.id));
res.status(400);
res.end();
}
});
});
存储库
function updateById(id, body, callback) {
var model = this.model;
var query = model.updateOne(
{
_id: id
},
{
body
});
query.exec(callback);
}
服务
updateOne: (id, body, callback) => {
UserRepository.updateById(id, body, (err, data) => {
callback(err, data);
})
}