gpt4 book ai didi

node.js - 通过(sails js)水线将值推送到mongodb数据库数组中

转载 作者:IT老高 更新时间:2023-10-28 13:18:00 25 4
gpt4 key购买 nike

Node js, sails js,水线。插入后我需要将值更新(或推送)到以下架构中

我正在使用带有水线和 mongodb 的sailsjs。

{
"countries": {
"states": [
{
"statename": "state",
"districts": [
{
"distname": "district",
"cities": [
{
"cityname": "Hyderabad",
"places": [
{
"placename": "hitechcity"
}
]

}
]
}
]
}
]
}
}

我需要知道如何更新它更新后我需要这样的东西

{
"countries": {
"states": [
{
"statename": "state",
"districts": [
{
"distname": "district",
"cities": [
{
"cityname": "Hyderabad",

"places": [
{
"placename": "hitechcity"
},
{
"placename": "someother place"
}
]

}
]
}
]
}
]
}
}

请有人帮助我。

最佳答案

好问题!你会想要使用 addToCollection():

await User.addToCollection(23, 'roles')
.members([3, 5, 6]);

在我的手机上完成,很抱歉有任何错别字:)

Edited Aug 7, 2018 to reflect best practices in Sails v1. More info: https://sailsjs.com/documentation/reference/waterline-orm/models/add-to-collection

关于node.js - 通过(sails js)水线将值推送到mongodb数据库数组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18161056/

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