首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MongoDB在多个subDocument中搜索多个字段

MongoDB在多个subDocument中搜索多个字段
EN

Stack Overflow用户
提问于 2021-02-13 04:03:01
回答 1查看 35关注 0票数 0

我的MongoDB数据结构如下所示:

代码语言:javascript
复制
    {
        "id": "7118592",
        "passages": [
             {
                 "infons": {
                     "article-id_pmid": "32292259",
                     "title": "Keywords",
                     "type": "front",
                     "section_type": "TITLE"
                  },
                  "text": "Understanding of guidance for acupuncture and moxibustion interventions on COVID-19 (Second edition) issued by CAAM"
             },
             {
                 "infons": {
                     "section_type": "ABSTRACT",
                     "type": "abstract",
                     "section": "Abstract"
                 },
                 "offset": 116,
                 "text": "At present, the situation of global fight against COVID-19 is serious. WHO (World Health Organization)-China Joint Mission fully confirms the success of \"China's model\" against COVID-19 in the report. In fact, one particular power in \"China's model\" is acupuncture and moxibustion of traditional Chinese medicine. To better apply \"non-pharmaceutic measures\":the external technique of traditional Chinese medicine, in the article, the main content of Guidance for acupuncture and moxibustion interventions on COVID-19 (Second edition) issued by China Association of Acupuncture-Moxibution is introduced and the discussion is stressed on the selection of moxibustion device and the duration of its exertion."
             }
         ]
    }

我想请求同一个子文档中的article-id_pmidtext,以及在infons中包含section_type : ABSTRACTtype: abstract字段的子文档的text

我已经尝试过此请求,但结果不是我要搜索的内容:

代码语言:javascript
复制
db.mydata.find({$and:[{"passages.infons.article-id_pmid$":{$exists: true}},{"passages.infons.section_type":"ABSTRACT"},{"passages.infons.type":"abstract"}]},{"passages.infons.article-id_pmid.$":1,_id:0, "passages.text":1})
EN

回答 1

Stack Overflow用户

发布于 2021-02-13 07:44:13

每个顶级条件都是独立处理的。

使用https://docs.mongodb.com/manual/reference/operator/query/elemMatch/在同一数组元素上指定多个条件。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66178366

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档