gpt4 book ai didi

javascript - 无法将数据推送到 mongo 数据库内的当前对象

转载 作者:太空宇宙 更新时间:2023-11-04 03:06:30 25 4
gpt4 key购买 nike

我使用的是 mongodb native 和 Node.js 6.5.0。

我在 mongodb 中有用户对象,其结构如下:

{ 
"_id" : ObjectId("57d7d294d96a73d128c46db9"),
"id" : "105862592064",
"labels" : [

]
}

我有一个循环(对于找到的每个用户)从 API 获取数据,然后将其推送到数组类型的对象属性中。其中用户 ID user.id 和要推送的数据是 resp.labels

这是我的代码:

db.collection('users').update(
{"id":user.id},
{"$push":{"users.labels":resp.labels}}
)

它不会返回任何错误,也不更新对象。我做错了什么?

最佳答案

Try this:

db.collection('users').update(
{"id":user.id},,
{
$push: {
labels: {
$each: //yourArray
}
}
}
);

关于javascript - 无法将数据推送到 mongo 数据库内的当前对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39467776/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com