title: How to Make a Lookup connection between two Collection
body: <p>Goal:<br>
  This sql and its result should be the same result from mongoDB's query code.<br>
   In order words, same result but for mongoDB.</p>
  
  <p>Problem:<br>
  How to you make a lookup connection in relation to <strong>People</strong> and <strong>Role</strong> in Mongo DB's query code?  </p>
  
  <p>Info:<br>
  I'm new in mongo DB  </p>
  
  <pre><code>SQL code 
      SELECT 
          a.*,
          '.' AS '.',
          b.*,
          '.'  AS '.',
          c.*
      FROM 
          [db1].[dbo].[People_Course_Grade] a
          INNER JOIN [db1].[dbo].[People] b on a.PeopleId = b.PeopleId
          INNER JOIN [db1].[dbo].[Role] c on b.RoleId = c.RoleId
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/NFt99.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NFt99.png" alt="enter image description here"></a></p>
  
  <p>Json data:  </p>
  
  <pre><code>Role:  
  [{"RoleId":1,"Name":"Student"},{"RoleId":2,"Name":"Teacher"}]
  
  People_Course_Grade:   
  [{"People_Course_GradeId":1,"PeopleId":1,"CourseId":1}, 
   {"People_Course_GradeId":2,"PeopleId":2,"CourseId":1}, 
   {"People_Course_GradeId":3,"PeopleId":3,"CourseId":2}, 
   {"People_Course_GradeId":4,"PeopleId":1,"CourseId":2}]
  
  Course:
  [{"CourseId":1,"Name":"Java"},{"CourseId":2,"Name":"Java II"}, 
   {"CourseId":3,"Name":"Statistik 1"}]
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/lVQZ5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lVQZ5.png" alt="Mongo db"></a></p>
  
  <pre><code>db.People_Course_Grade.aggregate([
  
      {
          $lookup:{
              from: "People",            
              localField: "people_id",   
              foreignField: "_id",       
              as: "people"               
          }
      },
      {   $unwind:"$people" },   
  
  
      {   
          $project:{
              course_id : 1,
              people_id : 1,
        //      grade_id : 1,
              Name : "$people.Name",
  
  
          } 
      }
  
  ]);
  </code></pre>