title: Does AWS DocumentDB Support Joining 3+ Collections In a Single Query?
body: <p>Is it possible to join 3 separate collections together in AWS DocumentDB with a single query (similar to the solution to the thread here: <a href="https://stackoverflow.com/a/66032673/14640164">How can I perform nested “joins” (joining 3 or more collections) in a MongoDB aggregation pipeline?</a></p>
  <p>I feel like it may not, but I don't think AWS comes right out and specifically says so anywhere.</p>
  <p>The <a href="https://docs.aws.amazon.com/documentdb/latest/developerguide/functional-differences.html#functional-differences.lookup" rel="nofollow noreferrer">Developer Guide</a> says:</p>
  <blockquote>
  <p>Amazon DocumentDB supports the ability to do equality matches (for
  example, left outer join) but does not support uncorrelated
  subqueries.</p>
  </blockquote>
  <p>That would be more helpful if I knew what an &quot;uncorrelated subquery&quot; was.</p>
  <p>Also, the <a href="https://docs.aws.amazon.com/documentdb/latest/developerguide/mongo-apis.html#mongo-apis-aggregation-pipeline-variable" rel="nofollow noreferrer">list of MongoDB APIs that DocumentDB supports</a> says that <code>$let</code> variable operator is outright not supported. Is the <code>$let</code> variable operator they're referring to exactly the same as the <code>let</code> expression within the <code>$lookup</code> stage that's used in the following query to join together 3 collections?</p>
  <pre><code>db.customers.aggregate([
    {
      $lookup: {
        from: &quot;orders&quot;,
        let: { customer_id: &quot;$customer_id&quot; },
        pipeline: [
          { $match: { $expr: { $eq: [&quot;$$customer_id&quot;, &quot;$customer_id&quot;] } } },
          {
            $lookup: {
              from: &quot;orderitems&quot;,
              localField: &quot;order_id&quot;,
              foreignField: &quot;order_id&quot;,
              as: &quot;items&quot;
            }
          }
        ],
        as: &quot;orders&quot;
      }
    }
  ])
  </code></pre>
  <p>Is joining 3+ collections within a single NoSQL query possible in AWS DocumentDB, and if not, what would be the recommended / most efficient way to do this?</p>