gpt4 book ai didi

node.js - 使用 Node JS 更新 mongoDB 集合中的值

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

我是 mongoDB 的新手,我发现了如何使用 Node JS 在 mongoDB 中插入和检索值。当我从集合中检索值时,我得到如下值。

[{"1":["muthu","Pandiyan"],"_id":"5d7a23cdeee1c2ca3bf52a76"},{"2":["muthu","raj","ram","rifas"],"_id":"5d7a23cdeee1c2ca3bf52a77"},{"3":["pandiyan","jeni","raj"],"_id":"5d7a23cdeee1c2ca3bf52a78"}]

我想将键 "1" 数组中的值更新为 ["muthu","Pandiyan","newuser"] 并且我尝试了以下操作代码,但我没有得到想要的结果。我觉得我在 updateOne 查询的第一个参数中犯了错误。有遗漏的地方请指正。

var r = yield db.collection('dummy3qa').updateOne({"1"},{$addToSet:"newuser"});
断言.equal(null, err);

最佳答案

你可以试试这个。引用这个https://docs.mongodb.com/manual/reference/method/db.collection.update/

db.dummy3qa.update(
{'1'},
{ $addToSet:"newuser"}
)

关于node.js - 使用 Node JS 更新 mongoDB 集合中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57958238/

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