Join data collection MongoDB inside an array and two element result add array element

I retrieve template collection by _id and by RevisionNum value.

I have document like this in a collection called **Template** :

{
_id: ObjectId(‘613f16eda156d84fd428510f’),
Templates: [
{
RevisionNum: “210719”,
EffectiveDate: 2021-07-19T17:43:06.693+00:00,
HardwareVer: “A”,
SoftwareVer: “1.0”,
WorkTasks: [“ObjectId(‘abce16eda156d84fd428510f’)”],
HasTraveller: true
},
{
RevisionNum: “210908”,
EffectiveDate: 2021-07-19T17:43:06.693+00:00,
HardwareVer: “AA”,
SoftwareVer: “11.0”,
WorkTasks: [ “ObjectId(‘wdfe16eda156d84fd428510f’)”,],
HasTraveller: true
},
]
}
The id inside the WorkTasks object array is from a separate collection called worktasks, see sample document below :

{
_id: ObjectId(‘abce16eda156d84fd428510f’),
Name: “Box Assembly”,
CanPerform: [ “Benjamin”, “Shirley” ],
InstructionFiles: [
{
Name: “Assembly.pdf”,
MimeType: “application/pdf”,
Path: “path_to_the_file”,
},
]
}

I am trying to create a mongodb query using the native node.js driver to get a result like this:

{
“TemplateDetails”: {
“HardwareVer”: “A”,
“SoftwareVer”: “1.0”,
“RevisionNum”: “210719”,
“EffectiveDate”: 2021-07-19T17:43:06.693+00:00,
“HasTraveller”: true,
“WorkTasks”: [
{
Name: “Box Assembly”,
CanPerform: [ “Benjamin”, “Shirley” ],
“InstructionFiles”: [
{
“Name”: “Assembly.pdf”,
“MimeType”: “application/pdf”,
“Path”: “path_to_the_file”
},
]
},…//other workTask
] },
“RevisionNums”: [ “210719”, “210908” ]
}

Please read Formatting code and log snippets in posts and update your sample documents so that we can cut-n-paste into our system.