我正在使用axios向我的put
发送一个API
请求,这就是axios调用的外观:
index.jsx
.put(`${helper.baseURL}/user/edit-userType/${ids}`, body, {
headers: { Authorization: header }
})
body
可以是这两个对象{ banned: true }
或{ userType: "publisher"}
在后端完美接收对象,这是其中的两个,这是API
user.js
router.put(
`${prefix}/edit-userType/:id`,
tokenController.ensureToken,
(req, res) => {
let body = req.body;
let ids = req.params.id.split(",");
let newDate = new Date();
body.updatedAt = newDate;
console.log("body", body); <<<< This returns { banned: false, updatedAt: 2018-07-13T02:29:30.619Z } OR { userType: "publisher", updatedAt: 2018-07-13T02:29:30.619Z }
modelUser.update(
{
_id: {
$in: ids
}
},
{
$set: {
body <<<<< this is not updating my user :(
}
},
(err, user) => {
Stuff...
}
);
}
);
我不知道为什么body
与用户架构具有相同的key: value
而不更新。
userSchema.js
const userSchema = new Schema({
a lot of: boring stuff,
userType: { type: String, default: "regular" },
banned: { type: Boolean, default: false },
boring stuff: again
})