using mongodb $lookup with array
<p>I am trying to merge the contents of a <strong>configurations</strong> collection with a configurations array within a <strong>companies</strong> collection. So company.configurations is an array, where each element has a reference to an _id in the configurations collection.</p>

<pre><code>&gt; db.configurations.find();
{
    "_id" : ObjectId("57518eea52feed9c4f70fc42"),
    "name" : "some_config_flag",
    "area" : "application",
    "default_value" : false
}
{
    "_id" : ObjectId("57518f8f52feed9c4f70fc43"),
    "area" : "application",
    "name" : "some_config_date"
}

&gt; db.companies.find();
{
    "_id" : ObjectId("5751935952feed9c4f70fc45"),
    "name" : "Demo",
    "configurations" : [
        {
            "configuration_id" : ObjectId("57518eea52feed9c4f70fc42"),
            "value" : false
        }
     ]
}
{
    "_id" : ObjectId("57519716fe1cc8d0575bcdfc"),
    "name" : "Acme",
    "configurations" : [
        {
            "configuration_id" : ObjectId("57518eea52feed9c4f70fc42"),
            "value" : true
        },
        {
            "configuration_id" : ObjectId("57518f8f52feed9c4f70fc43"),
            "value" : ISODate("2016-06-30T00:00:00Z")
        }
    ]
}
&gt;
</code></pre>

<p>I've tried using $lookup to achieve this, but the lookup references remain empty:</p>

<pre><code>db.companies.aggregate([
{
    $lookup:{
        from:"configurations",
        localField:"_id",
        foreignField: "configuration_id",
        as: "configuration"
    }
 }])

db.companies.aggregate([
{
    $lookup:{
        from:"configurations",
        localField:"_id",
        foreignField: "configurations.configuration_id",
        as: "configuration"
    }
 }])
</code></pre>

<p>Also switching the localField &amp; foreignField doesn't help. Is $lookup intended to support this kind of query or would it something to resolve as part of the application code?</p>