title: Conditional $match MongoDB
body: <p>I'm new to Mongo Queries and I can't really get this bit to work.</p>
  
  <p>I have a query where I am trying to execute a part where I need to check for a variable and then match.</p>
  
  <pre><code>const FIRST_SUBJECT = keywords_list[0].subjects || {"$ne":null};
  
  .
  .
  .
  
  {'$match': {'entities.qcode': FIRST_SUBJECT}},
  
  </code></pre>
  
  <p>In the above, I want to execute the $match only if <code>FIRST_SUBJECT</code> is not empty or null.</p>
  
  <p>I have tried a <code>$cond</code> inside the <code>$match</code> and vice-a-versa but they both throw errors</p>
  
  <p>In simple terms :</p>
  
  <pre><code>if(FIRST_SUBJECT)
  $match
  else
  skip $match
  </code></pre>
  
  <p>How to achieve this?</p>