title: Two queries or aggregate lookup for MongoDB inner join
body: <p>I have two collections: Manager and Venue.</p>
  
  <p><strong>Manager document example</strong></p>
  
  <pre><code>{
   "_id":"5d4f84dd4c35350b284b08ea",
  "Name":"Name",
  "Surname":"Surname",
  "Username":"Username",
  "Password":"123456",
  "CreatedDate":"2019-08-11T03:00:44.981Z"
  }
  </code></pre>
  
  <p><strong>Venue document example</strong></p>
  
  <pre><code>{
  "_id":"5d4f84de4c35350b284b08eb",
  "Name":"Name",
  "Manager":"5d4f84dd4c35350b284b08ea",
  "CreatedDate":"2019-08-11T03:00:46.598Z"
  }
  </code></pre>
  
  <p>I learned that there are two ways to do inner join</p>
  
  <p><strong>First way</strong></p>
  
  <p>solve this problem in two queries</p>
  
  <pre><code>var manager = db.manager.findOne({"id" : "5d4f84dd4c35350b284b08ea"})
  
  var venue = db.venue.findOne({"id" : manager.id})
  </code></pre>
  
  <p><strong>Second way</strong></p>
  
  <p>To have everything with just one query using the $lookup feature of the aggregation framework</p>
  
  <pre><code>db.Manager.aggregate(
      [
          {
              $lookup:
              {
                  from: "Venue",
                  localField: "localField",
                  foreignField: "_id",
                  as: "as"
              }
          },
      ]
  )
  </code></pre>
  
  <p><a href="https://stackoverflow.com/questions/4563205/how-to-join-query-in-mongodb/4588699">Reference Link</a></p>
  
  <p>here is the question</p>
  
  <p>Second way is more suitable for me but I'm not sure which way to use, can you help me.</p>