使用 feathersjs 创建后无法从对象中删除 _id 字段
Unable to delete _id field from object after create using feathersjs
我想在插入数据后修改节点应用程序中的 hook.data 对象。其实我做不到。
create: [function(hook, next) {
delete hook.data._id;
hook.data = { problem: hook.data }
postJson(hook.app.get('jsprintUrl'), hook.data)
.then(data =>{
hook.result = data;
next()
})
}]
结果: _id 仍然存在
{
"_id": "59ca334e7bc4e06b140aadf9",
"algorithm": [
{
"name": "SA"
}
]
}
我按以下方式使用 hook.result 更新对象,hook.result 会将其 Mongoose 文档转换为普通对象。更多信息 reference link
create: [function(hook, next) {
delete hook.result._id;
hook.result = { problem: hook.result }
postJson(hook.app.get('jsprintUrl'), hook.result)
.then(data =>{
hook.result = data;
next()
})
}]
结果:已从响应中删除
{
"algorithm": [
{
"name": "SA"
}
]
}
我想在插入数据后修改节点应用程序中的 hook.data 对象。其实我做不到。
create: [function(hook, next) {
delete hook.data._id;
hook.data = { problem: hook.data }
postJson(hook.app.get('jsprintUrl'), hook.data)
.then(data =>{
hook.result = data;
next()
})
}]
结果: _id 仍然存在
{
"_id": "59ca334e7bc4e06b140aadf9",
"algorithm": [
{
"name": "SA"
}
]
}
我按以下方式使用 hook.result 更新对象,hook.result 会将其 Mongoose 文档转换为普通对象。更多信息 reference link
create: [function(hook, next) {
delete hook.result._id;
hook.result = { problem: hook.result }
postJson(hook.app.get('jsprintUrl'), hook.result)
.then(data =>{
hook.result = data;
next()
})
}]
结果:已从响应中删除
{
"algorithm": [
{
"name": "SA"
}
]
}