How to select only matched sub-document of mongodb using python

前端 未结 2 1615
深忆病人
深忆病人 2021-01-03 17:14
Document in Mongo ->

            {
             emp_id : 11
             proj_info : 
                    [{
                     proj_id : 91
                           


        
2条回答
  •  心在旅途
    2021-01-03 17:37

    welcome to Stackoverflow, you can use ${project} method to reduce it to the scope of the subdocument and then you can use ${match} there, like this:

    collectionObject.aggregate([
    {'$match':"emp_id":'11'}},
    {'$project': {"proj_info": 1}},
    {'$match':"proj_id":'91'}},
    {'$project': {"proj_team": 1}},
    {'$match': {"member_emp_id":'55'}}])
    

提交回复
热议问题