title: Using LINQ to join multiple MongoDB collections
body: <p>I have some trouble on how to join data in the following silly thought up example:</p>
  <p>I have 3 collections:</p>
  <pre><code>Pets: [{
      &quot;_id&quot;: ObjectId,
      &quot;Name&quot;: string,
      &quot;BodyParts&quot;: [{ &quot;GroupId&quot;: ObjectId }]
  }]
  
  BodyParts: [{
      &quot;_id&quot;: ObjectId,
      &quot;PartName&quot;: string,
      &quot;Colors&quot;: [{ &quot;ColorId&quot;: ObjectId }]
  }]
  
  Colors: [{
      &quot;_id&quot;: ObjectId,
      &quot;ColorName&quot;: string
  }]
  </code></pre>
  <p>It's very relational and Mongo may not be the best choice for this, but that's the situation I have.</p>
  <p>I'd like to have a method where a Pet ID is provided and which returns a class something like this:</p>
  <pre><code>Pet GetPet(string petId)
  {
      var data = _mongoCollection.FancyLINQ(petId);
      return new Pet(...);
  }
  
  class Pet
  {
      string Id;
      string Name;
      List&lt;BodyPart&gt; BodyParts;
  }
  
  class BodyPart
  {
      string Id;
      string PartName;
      List&lt;Color&gt; Colors;
  }    
  
  class Color
  {
      string Id;
      string ColorName;
  }
  </code></pre>
  <p>This could probably easily be done by sending 3 requests to Mongo and then assembling the data. One to find pet and it's list of body parts ids. A second to look up the parts and extract the colors. A thirds to look up the colors.</p>
  <p>But that doesn't sound optimal. I can also use some native MongoDb syntax, but I'm not comfortable with this.</p>
  <p>I'd prefer if this is possible using LINQ. I know joins can be done, but I haven't managed to find a way that solves my challenge above.</p>
  <p>Bonus: if it can be constructed using LINQ, will it then, under the hood, call the database multiple times? Or only once, which I hope for.</p>
  <p>I'm using the (at the time of writing) newest driver (2.17.1) and MongoDB version (6).</p>