exclusion1 = list(self.dw['CQM2018'].aggregate([
{'$match': {'_id': {'$in': denom_id}}},
{'$project': {'ClinicID': 1, 'PatientID': 1,
'Depression_diagnosis': 1, 'Bipolar_Diagnosis': 1, 'Depression_Screening_Encounter_Codes': 1}},
{'$unwind': {'path': '$Depression_diagnosis', 'preserveNullAndEmptyArrays': True}},
{'$unwind': {'path': '$Bipolar_Diagnosis', 'preserveNullAndEmptyArrays': True}},
{'$unwind': {'path': '$Depression_Screening_Encounter_Codes'}},
{'$project': {'ClinicID': 1, 'PatientID': 1,
'compare1': {'$cond': {'if': {'$gt': ['$Depression_diagnosis.DOS', None]}, 'then': {'$lte': ['$Depression_diagnosis.DOS', '$Depression_Screening_Encounter_Codes.DOS']}, 'else': False}},
'compare2': {'$cond': {'if': {'$gt': ['$Bipolar_Diagnosis.DOS', None]}, 'then': {'$lte': ['$Bipolar_Diagnosis.DOS', '$Depression_Screening_Encounter_Codes.DOS']}, 'else': False}},
}},
{'$match': {'$or': [{'compare1': True}, {'compare2': True}]}},
]))
如果這里的compare1、compare2有好幾十個類似的,有沒有什么簡便的方法。需求就是查出滿足眾多條件中的任意一項的資料
uj5u.com熱心網友回復:
《Mongo計算難點總結歸納》這篇文章有一部分內容是關于分組聚合的轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/75211.html
標籤:MongoDB
上一篇:華為鴻蒙系統初探之HUAWEI DevEco Studio Hello World
下一篇:MongoDB統計嵌套子表條數
