title: is it possible to write regular expression in $cond in MongoDB
body: <p>I need to use $cond to combine differenet column, and one $cond I need to write is as following:</p>
  
  <pre><code>create_widget: {
          $sum:{
            $cond:[{$and: [ {$eq: ['$Method', 'POST']},
                  {Url:{$regex: /.*\/widgets$/}} ]}, 1, 0]
          }
      }
  </code></pre>
  
  <p>and this code is not right, it seems, regular expression can not be put here.Is there any other way to do this? I want to match Url and regular expression and put the code under $cond.</p>
  
  <p>A sample data looks as </p>
  
  <pre><code>{"BrandId":"a","SessionId":"a1","Method":"POST","Url":"/sample/widgets"}
  {"BrandId":"a","SessionId":"a2","Method":"POST","Url":"/sample/blog"}
  {"BrandId":"b","SessionId":"b1","Method":"PUT","Url":"/sample/widgets"}
  </code></pre>
  
  <p>The whole code I wrote is as following:</p>
  
  <pre><code>db.tmpAll.aggregate([
      {$group: {
          _id: {BrandId:'$BrandId'},
          SessionId: {$addToSet: '$SessionId'},
          create_widget: {
              $sum:{
                $cond:[{$and: [ {$eq: ['$Method', 'POST']},
                      {} ]}, 1, 0]
              }
          }
      }},
      {$group: {
          _id: '$_id.BrandId',
          distinct_session: {$sum: {$size: '$SessionId'}},
          create_widget: {$sum: '$create_widget'}
      }}
  ]);
  </code></pre>
  
  <p>The expected result of sample code is</p>
  
  <pre><code>{ "_id" : "a", "distinct_session" : 2, "create_widget" : 1 }
  { "_id" : "b", "distinct_session" : 1, "create_widget" : 0 }
  </code></pre>