title: Query MongoDB with $and and Multiple $or
body: <p>As stated in the <a href="https://docs.mongodb.com/manual/reference/operator/query/and/" rel="noreferrer">documentation</a>, this is not possible.</p>
  <hr />
  <h1>AND Queries With Multiple Expressions Specifying the Same Operator</h1>
  <p>Consider the following example:</p>
  <pre><code>db.inventory.find( {
      $and : [
          { $or : [ { price : 0.99 }, { price : 1.99 } ] },
          { $or : [ { sale : true }, { qty : { $lt : 20 } } ] }
      ]
  } )
  </code></pre>
  <p>This query will return all select all documents where:</p>
  <p>the price field value equals 0.99 or 1.99, and
  the sale field value is equal to true or the qty field value is less than 20.</p>
  <p><em><strong>This query cannot be constructed using an implicit AND operation, because it uses the $or operator more than once.</strong></em></p>
  <hr />
  <p>What is a workaround to query something like this? This query returns no results on MongoDB 3.2. I have tested the $or blocks separately and they are working fine, but not when they are wrapped in $and block. I assumed I didn't read the documentation incorrectly that this is not supposed to work. The only alternative I have is to push the data to ElasticSearch and query it there instead, but that's also just a workaround.</p>
  <pre><code>{
      &quot;$and&quot;: [
          {
              &quot;$or&quot;: [
                  {
                      &quot;title&quot;: {
                          &quot;$regex&quot;: &quot;^.*html .*$&quot;,
                          &quot;$options&quot;: &quot;i&quot;
                      }
                  },
                  {
                      &quot;keywords&quot;: {
                          &quot;$regex&quot;: &quot;^.*html .*$&quot;,
                          &quot;$options&quot;: &quot;i&quot;
                      }
                  }
              ]
          },
          {
              &quot;$or&quot;: [
                  {
                      &quot;public&quot;: true
                  },
                  {
                      &quot;domain&quot;: &quot;cozybid&quot;
                  }
              ]
          }
      ]
  }
  </code></pre>