gpt4 book ai didi

javascript - MongoDB查询数组的数组里面的字段

转载 作者:行者123 更新时间:2023-11-30 11:34:35 25 4
gpt4 key购买 nike

{
"_id": 1,
"posts":[
{
"_id": 1,
"title": "my title",
"content": "some post content here...",
"comments": [
{
"_id": 1,
"text": "my comment"
},
{
"_id": 2,
"text": "your_comment"
}
]
}
]
}

在这里,我将如何查询/获取与 comments 数组的 text 字段中的文本“my comment”匹配的文档。

最佳答案

您可以使用这个简单的查询来查找:

{
"posts.comments.text": "my comment"
}

关于javascript - MongoDB查询数组的数组里面的字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45011407/

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