【发布时间】:2020-12-20 13:03:37
【问题描述】:
This is my mongodb collection.
我想用 findOneAndUpdate() 将对象推送到数组。
这是我的 nodejs 代码。
url = req.params.posturl
filter = { url: url }
update = { comments: (result.like + 1) }
// maybe you can try save/get this to/in .json
Blog.findOneAndUpdate(filter, update)
.then((result) => {
res.json({ status: 1 })
})
.catch((error) => {
console.log(error);
})
我该怎么做?
【问题讨论】:
-
cmets 数组的外观如何?你的输入
result变量包含什么?请尝试发布文档而不是图片。
标签: javascript node.js arrays mongodb