【发布时间】:2020-01-22 20:54:36
【问题描述】:
我正在使用 nodeJS 和猫鼬。我想向 mongoose 查询返回的现有对象添加新键。
Poll.findById(eid)
.then(poll => {
poll['newField']=['value1', 'value2'];
res.send(poll);
})
.catch(err=>console.log(err))
此代码显示以前的 poll 值,没有新字段。但是当我 res.send(poll["newField"]) 我可以看到 ["value1","value2"] 作为输出。如何使用 newField 制作 res.send(poll) 显示对象?
【问题讨论】:
-
你试过
Poll.findById(eid).lean().then(...) -
那行得通。解决了!