Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MongoDB在多个子文档中搜索多个字段_Mongodb_Nosql_Bigdata_Projection_Subdocument - Fatal编程技术网

MongoDB在多个子文档中搜索多个字段

MongoDB在多个子文档中搜索多个字段,mongodb,nosql,bigdata,projection,subdocument,Mongodb,Nosql,Bigdata,Projection,Subdocument,我的MongoDB数据结构如下所示: { "id": "7118592", "passages": [ { "infons": { "article-id_pmid": "32292259", &

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

    {
        "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\u pmid
text
,以及子文档的
text
,该子文档在
infons
中包含一个带有
节类型:ABSTRACT
类型:ABSTRACT
的字段
我尝试过这个请求,但结果不是我要搜索的:

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})

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


用于在同一数组元素上指定多个条件。

passeges
是一个数组,因此执行
通道。infons…
将不起作用。
passions
数组中是否总是只有2个元素?意思是说它里面总是只有2个子文档吗?不,
passions
在同一时间可以有2个以上的元素,并且不是所有的
infons
都包含
article-id\u-pmid
,这就是为什么我试图过滤它们
db.mydata.find({$and:[{“passions”:{$elemMatch:{“infons.article-id_pmid”:{“$exists”:true}}}},{“passions”:{“$elemMatch”:{“infons.section_type”:“ABSTRACT”,“infons.type”:“ABSTRACT”}}},{“passions.infons.article-id_pmid”:1})
谢谢,我已经试过了,但是新的问题是如何只显示
article-id\u pmid
和另一个子文档
infons
的文本,类型为
abstract
!!!