title: Unrecognized pipeline stage name: '$and'
body: <p>I was trying to run two filters for counting the number of male and females in my table. I was already able to filter and count either male or females on my table with</p>
  
  <pre><code>db.employee.aggregate({$match:{"gender":"male"}},{$count:"Males"})
  </code></pre>
  
  <p>or</p>
  
  <pre><code>db.employee.aggregate({$match:{"gender":"female"}},{$count:"Females"})
  </code></pre>
  
  <p>Now, I was just trying to combine this two commands into one single command. How is it done in Mongodb with $and ?, I have the following code</p>
  
  <pre><code>db.employee.aggregate(
   { $and : 
   [  
   {$match:{"gender":"male"}},{$count:"Males"}
   ,
   {$match:{"gender":"female"}},{$count:"Females"}
   ]
   }   
   )
  </code></pre>
  
  <p>and its throwing this error:</p>
  
  <pre><code>E QUERY    [js] Error: command failed: {
      "ok" : 0,
      "errmsg" : "Unrecognized pipeline stage name: '$and'",
      "code" : 40324,
      "codeName" : "Location40324"
  } : aggregate failed :
  _getErrorWithCode@src/mongo/shell/utils.js:25:13
  doassert@src/mongo/shell/assert.js:18:14
  _assertCommandWorked@src/mongo/shell/assert.js:536:17
  assert.commandWorked@src/mongo/shell/assert.js:620:16
  DB.prototype._runAggregate@src/mongo/shell/db.js:260:9
  DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1062:12
  @(shell):1:1
  </code></pre>
  
  <p>What did I do wrong here though?, alredy look on the mondodb documenations, still can't determine why it is erroring out.</p>
  
  <p>I'm following this syntax format based on the documentation though.</p>
  
  <pre><code>db.&lt;collection_name&gt;.aggregate({
   $and : [
   { &lt;condition1&gt;} , {condition2}
   ]
   } )
  </code></pre>
  
  <p>My Database contents could be created with the ff. script.:</p>
  
  <pre><code>db.employee.insert([
      {"id":"1","name": "Ricardo Carpio","age": 24, "gender": "male", "birthYear" : "1995" , "hobby" : "Reading books"},
      {"id":"2","name": "Alice Salpicao","age": 27, "gender": "female", "birthYear" : "1992" , "hobby" : "Eating"},
      {"id":"3","name": "Cardo Agustin","age": 25, "gender": "male", "birthYear" : "1996" , "hobby" : "Jogging"},
      {"id":"5","name": "Gamora Yuchi","age": 24, "gender": "female", "birthYear" : "1995" , "hobby" : "Singing"},
      {"id":"6","name": "Thanos Pink","age": 29, "gender": "male", "birthYear" : "1990" , "hobby" : "Collecting gems"}
  ]) 
  </code></pre>