title: How to query an array for different combinations of ANDs and ORs in MongoDB Aggregation?
body: <p>I am trying to search for list of students who have completed courses using different combinations of Logical ANDs and ORs.</p>
  
  <p>For example I want to get student who completed ("Course 1" and "Course 2") or "Course 3"</p>
  
  <p>Here is my data structure for each student : </p>
  
  <pre><code>{
        "_id" : ObjectId("5c68841cb6b18f31975c8fb0"),
        "courses" :  [ 
             "Course 1", "Course 4"
          ]
  }
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>db.getCollection('users').aggregate([
      {
          $match: { 
              "courses": {
                  $or: {
                      $all: ["Course 1","Course 2"],
                      $in : ["Course 3"]
                   }
              }
          }
      }
  ])
  </code></pre>
  
  <p>I have tried to nest different operators ( <code>$all</code>, <code>$in</code>, <code>$and</code>, <code>$or</code> ) and failed.</p>