MongoDB join data inside an array of objects
<p>I have document like this in a collection called <strong>diagnoses</strong> :</p>

<pre><code>   {
        "_id" : ObjectId("582d43d18ec3f432f3260682"),
        "patientid" : ObjectId("582aacff3894c3afd7ad4677"),
        "doctorid" : ObjectId("582a80c93894c3afd7ad4675"),
        "medicalcondition" : "high fever, cough, runny nose.",
        "diagnosis" : "Viral Flu",
        "addmissiondate" : "2016-01-12",
        "dischargedate" : "2016-01-16",
        "bhtno" : "125",
        "prescription" : [ 
            {
                "drug" : ObjectId("58345e0e996d340bd8126149"),
                "instructions" : "Take 2 daily, after meals."
            }, 
            {
                "drug" : ObjectId("5836bc0b291918eb42966320"),
                "instructions" : "Take 1 daily, after meals."
            }
        ]
    }
</code></pre>

<p>The <strong>drug</strong> id inside the prescription object array is from a separate collection called <strong>drugs</strong>, see sample document below :</p>

<pre><code>{
    "_id" : ObjectId("58345e0e996d340bd8126149"),
    "genericname" : "Paracetamol Tab 500mg",
    "type" : "X",
    "isbrand" : false
}
</code></pre>

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

<pre><code>        {
                "_id" : ObjectId("582d43d18ec3f432f3260682"),
                "patientid" : ObjectId("582aacff3894c3afd7ad4677"),
                "doctorid" : ObjectId("582a80c93894c3afd7ad4675"),
                "medicalcondition" : "high fever, cough, runny nose.",
                "diagnosis" : "Viral Flu",
                "addmissiondate" : "2016-01-12",
                "dischargedate" : "2016-01-16",
                "bhtno" : "125",
                "prescription" : [ 
                    {
                        "drug" : 
                        {
                          "_id" : ObjectId("58345e0e996d340bd8126149"),
                          "genericname" : "Paracetamol Tab 500mg",
                          "type" : "X",
                          "isbrand" : false
                        },
                        "instructions" : "Take 2 daily, after meals."
                    },
                    ...
                ]
            }
</code></pre>

<p>Any advice on how to approach a similar result like this is much appreciated, thanks.</p>