如何解决MongoDB 在多个子文档中搜索多个字段
我的 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_pmid
和 text
,还有 text
子文档中包含 infons
字段的 section_type : ABSTRACT
和type: 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})
解决方法
每个顶级条件都是独立处理的。
使用 https://docs.mongodb.com/manual/reference/operator/query/elemMatch/ 对同一个数组元素指定多个条件。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。