title: MongoDB: Select from one collection based on another collection
body: <p>I'm new to MongoDB and I'm trying to find a category that meets the required params. I have two collections, categories (list of categories) and ref_categories (manages nested category relationships)</p>
  <pre><code>collection categories:
  [
    {
        &quot;id&quot;: &quot;A1001&quot;,
        &quot;key&quot;: &quot;3dmodels&quot;,
    },
    {
        &quot;id&quot;: &quot;A1002&quot;,
        &quot;key&quot;: &quot;animals&quot;,
    },
    {
        &quot;id&quot;: &quot;A1003&quot;,
        &quot;key&quot;: &quot;birds&quot;,
    },
    {
        &quot;id&quot;: &quot;A1004&quot;,
        &quot;key&quot;: &quot;reptiles&quot;,
    },
    {
        &quot;id&quot;: &quot;A1005&quot;,
        &quot;key&quot;: &quot;birds&quot;,
    }
  ]
  
  collection categories_ref:
  [
    {
        &quot;category_id&quot;: &quot;A1001&quot;, // 3dmodels parented to
        &quot;p_category_id&quot;: &quot;root&quot;, // root
    },
    {
        &quot;category_id&quot;: &quot;A1002&quot;, // animals parented to
        &quot;p_category_id&quot;: &quot;A1001&quot;, // 3dmodels
    },
    {
        &quot;category_id&quot;: &quot;A1003&quot;, // birds parented to
        &quot;p_category_id&quot;: &quot;A1002&quot;, // animals
    },
    {
        &quot;category_id&quot;: &quot;A1004&quot;, // reptiles parented to
        &quot;p_category_id&quot;: &quot;A1002&quot;, // animals
    },
    {
        &quot;category_id&quot;: &quot;A1005&quot;, // birds parented to
        &quot;p_category_id&quot;: &quot;A1004&quot;, // reptiles
    }
  ]
  </code></pre>
  <p>You'll noticed in my Categories collection there are two entries for 'birds' however they each have a different parent category.</p>
  <p>I'm trying to create a query that allows me to find the category by key and parent category key.</p>
  <p>Pseudo example.... I want to find 'birds' but the entry who has a parent called 'animals'. Otherwise return null.</p>
  <p>the expected output would be</p>
  <pre><code>// find category_key: &quot;birds&quot; parent_category_key: &quot;animals&quot;
  
  {
     &quot;id&quot;: &quot;A1003&quot;,
     &quot;key&quot;: &quot;birds&quot;,
  }
  </code></pre>