Mongo多表關聯的子查詢

用於手機號條件過濾後手機號關聯再進行子查詢條件平臺爲今日頭條:

db.getCollection("robot_account_port_info").aggregate(
    [
        
        {
            //        查詢條件爲端口信號存在的
            "$match": {
                "port_sign": 1
            }
        },
        {
            //把另一張表【account】與用本地的手機號進行關聯
            "$lookup": 
            
            {
                "from": "account",
                "localField": "phone",
                "foreignField": "phone_num",
                "as": "inventory_docs"
            }
        },
        {
            //查處滿足條件的子文檔
            "$unwind": "$inventory_docs"
        },
        {
            //這兒是將子文檔展示出來,否則查處的結果滿足子文檔的其中之一,子文檔的值都會顯示出來
            "$match": {
                "inventory_docs.platform": "今日頭條"
            }
        },
        
    ]
)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章