title: Check if an element appears in an array during the projection stage of a mongo aggregation pipeline
body: <p>I've got a collection of mongo documents like - </p>
  
  <pre><code>{
      "_id" : "c959e4d6-961d-4043-ade6-2f93aa055e11",
      "events" : [
          "clickOut"
          "showHoverAd",
          "closeHoverAd"
      ]
  }
  { 
      "_id" : "d0dcb2be-f8bc-45cd-8337-d89a16063b08", 
      "events" : [ 
          "zoom",
          "pan"
      ] 
  }
  {
      "_id" : "9179b26e-e45c-48ab-93f6-e73b8ebe559b",
      "events" : [
          "clickOut"
      ]
  }
  {
      "_id" : "db0b82ad-7a33-4ce8-9117-f6ecf041d0d9",
      "events" : [
          "adjustStars",
          "adjustPrice",
          "closeHoverAd",
          "showHoverAd"
      ]
  }
  </code></pre>
  
  <p>I'm trying to use a projection stage in an aggregation pipeline to identify if a particular string appears in the events field. </p>
  
  <pre><code>db.events.aggreate([
      {$project: {
          session: '$_id',
          clickedOut: {
              $cond: [{$elemMatch: {'$events':'clickOut'}},true,false]
          }
      }}
  ])
  </code></pre>
  
  <p>I'm getting an error - <code>exception: invalid operator '$elemMatch'</code>.</p>
  
  <p>I want my output documents to look like -</p>
  
  <pre><code>{
      "session" : "c959e4d6-961d-4043-ade6-2f93aa055e11",
      "clickedOut" : false
  }
  { 
      "session" : "d0dcb2be-f8bc-45cd-8337-d89a16063b08", 
      "clickedOut" : true
  }
  </code></pre>
  
  <p>But I can't seem to find a way of doing it. I've tried using <code>$in</code> and <code>$all</code> or simply </p>
  
  <pre><code>$cond: {'$events':'clickOut'}
  </code></pre>
  
  <p>but I'm not getting anywhere.</p>