Horje
mongo db $lookup iterating over data Code Example
mongo db $lookup iterating over data
db.parent.aggregate([
    { $match: { "_id": "5e6cd8c1996ddf1c28e14505" } },
    {
        $lookup: {
            from: "childnodes",
            let: { "child_id": "$parentList.child_id", "activeid": "$parentList.active_id" },
            pipeline: [
                { $match: { "$expr": { $eq: ["$_id", "$$child_id"] } } },
                {
                    $project: {
                        "child_id": "$_id",
                        "start_date": "$startDate",
                        "current_version_Key": "$active",
                        "active_child_name": {
                            "$reduce": {
                                "input": { "$objectToArray": "$$ROOT" },
                                "initialValue": "",
                                "in": {
                                    "$cond": [{ "$eq": ["$$this.k", "$$activeid"] },
                                        "$$this.v.childName",
                                        "$$value"
                                    ]
                                }
                            }
                        },
                        "text": {
                            "$reduce": {
                                "input": { "$objectToArray": "$$ROOT" },
                                "initialValue": "",
                                "in": {
                                    "$cond": [{ "$eq": ["$$this.k", "$$activeid"] },
                                        "$$this.v.text",
                                        "$$value"
                                    ]
                                }
                            }
                        },
                        "type": {
                            "$reduce": {
                                "input": { "$objectToArray": "$$ROOT" },
                                "initialValue": "",
                                "in": {
                                    "$cond": [{ "$eq": ["$$this.k", "$$activeid"] },
                                        "$$this.v.type",
                                        "$$value"
                                    ]
                                }
                            }
                        }
                    }
                }
            ],
            as: "finalList",
        },
    },
    {
        $project: {
          parentList: 0,
        },
      },
]);




Whatever

Related
league download Code Example league download Code Example
iran Code Example iran Code Example
udp Code Example udp Code Example
getbestfx Code Example getbestfx Code Example
tomcat connector Code Example tomcat connector Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7