Mongo 3.2 join with specific item
<p>Imagine two collections in Mongo 3.2 called student and class.  What is the query that would return all student documents that are in a specific class.</p>

<p>The aggregate with $lookup seems to want to operate on all documents in the collection.  For instance returning all students in every class instead of the specific one.  </p>

<p><strong>How can I request the resulting student documents that are in a specific class with id=23945647b27e7e652a9aeb65?</strong></p>

<p>Class:</p>

<pre><code>{
    "_id" : ObjectId("23945647b27e7e652a9aeb65"),  // Given this
    "name" : "Algebra",
    "students" : [ "13945647b27e7e65869aeb65", "03945647b27e7e65029aeb65" ]
}
</code></pre>

<p>Student:  // Return this</p>

<pre><code>{
    "_id" : ObjectId("13945647b27e7e65869aeb65"), 
    "name" : "foo"
}
{
    "_id" : ObjectId("03945647b27e7e65029aeb65"), 
    "name" : "bar"
}
</code></pre>

<p>Some failed attempts:</p>

<pre><code>db.student.aggregate([{$match:{"$ref": "class", "_id": ObjectId("23945647b27e7e652a9aeb65")}},{$lookup:{from: "class",localField:"students",foreignField: "_id", as: "stuffFromRight"}}}])


db.student.aggregate([{$lookup:{from: {"$ref": "class", "_id": ObjectId("23945647b27e7e652a9aeb65")},localField:"students",foreignField: "_id", as: "stuffFromRight"}}])
</code></pre>

<p>This one gets PARTIAL credit as it does do the correct lookup.  BUT, ..., it does not limit the result to the specific class I want.</p>

<pre><code>db.student.aggregate([{$lookup:{from: "class",localField:"students",foreignField: "_id", as: "stuffFromRight"}}])
</code></pre>