因为我只想从一个函数更新很多键。 我需要了解如何将密钥设置为动态更新。
static async updateProfile(req, res, next) {
const userId = req.body.userId;
// I am receiving the key in body that needs to be updated
const key = req.body.key;
const value = req.body.value;
const toUpdate = {
userId: userId,
//here I want the key to be dynamic
key: value
};
try {
const updateNow = await Profile.findOneAndUpdate(
{ userId: userId },
toUpdate,
{ upsert: true }
);
} catch (err) {
console.log(err);
}
}
答案 0 :(得分:1)
axios.get('route', {
headers: {
Authorization: localStorage.getItem('jwt'),
'Content-Type': 'application/json',
'Cache-Control': 'no-cache'
}
})
.then(res => {
// do something
});