update接口返回的字段还是有多余?
来源:5-18 书籍修改操作(二)

慕勒8322402
2021-09-06
这个是update点击按钮的方法,传了对应的几个字段
const submit = async () => {
const res = await book.update({
id: props.book._id,
name: editForm.name,
price: editForm.price,
author: editForm.author,
publishDate: editForm.publishDate.valueOf(),
classify: editForm.classify
});
result(res)
.success(({
data,
msg
}) => {
context.emit('update', data);
message.success(msg);
close();
});
};
这个是update的后台接口
router.post('/update', async (ctx) => {
const {
id,
...others //剩下的属性
} = ctx.request.body;
const one = await Book.findOne({
_id: id
}).exec();
if (!one) {
ctx.body = {
msg: '没有找到书籍',
code: 0
}
return;
}
const newQuery = {};
Object.entries(others).forEach(([key, value]) => {
if (value) {
newQuery[key] = value;
}
});
Object.assign(one, newQuery);
const res = await one.save();
ctx.body = {
data: res,
code: 1,
msg: '保存成功'
};
});
但是返回的数据仍然是有多余的meta和__V这些字段?
写回答
1回答
-
然冬
2021-09-12
后端代码
const res = await one.save();
这里查询出来包含,手动剔除掉再响应。
012021-09-12
相似问题