gpt4 book ai didi

javascript - 插入mongodb中的一系列文件

转载 作者:行者123 更新时间:2023-11-30 20:23:48 28 4
gpt4 key购买 nike

使用哪个运算符将新问题推送到问题数组中?我得到了以下格式的文档。使用哪个 mongo db 运算符将新问题插入到问题数组中,前提是我在提前。

例如,我想在 subchapterId“1”中插入一个新问题。

  {

"chapterId": "38",
"subChapter": [
{

"subchapterId": "1",
"questions": [
{

"title": "Either his however modern. Stop central owner color type out. Interview five beyond interesting type suddenly.",

},
{

"title": "Amount himself foreign color moment gun together sit. Deal race range heart despite several. Rather activity eat dinner save mission western. Civil past public enter four then.",

},
{

"title": "Four former operation. Class continue away treatment.\nResponsibility condition dinner realize everything. Sign scene order quality yet. Within sing statement skill popular southern whole."

},
{

"title": "Where of coach nature ask page allow.\nType exist hotel time. Central site policy everyone safe. Official administration family somebody.",

},
{

"title": "Necessary dark these much region. Form sometimes seek. Future according detail piece section.\nNear everything admit. Senior Republican draw as expert market.",

}
]
},
{

"subchapterId": "2",
"questions": [
{

"title": "Audience still use group. Yourself building police. Play imagine serious reality population reach.\nHerself without member must think concern window finish."

},


{

"title": "Rule trip manage still. Imagine religious above race something successful.\nOnce base American series. Low page quite allow. Customer maybe base leave way under blood.",

},
{

"title": "Church audience anyone garden. Federal when individual style.Value billion morning need box whether. Coach traditional cold each us truth.",

}
]
}
]
}

最佳答案

你可以试试这个

const title = "this is the new question"

db.collection.update(
{ "subChapter.subchapterId": "1" },
{ "$push": { "subChapter.$.questions": { title } }}
)

关于javascript - 插入mongodb中的一系列文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51146516/

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