title: mongodb evaluate if string ends with another substring
body: <p>I would like to project a field with a value if another field ends with a substring but another value if it's not</p>
  
  <p>How can I do that?</p>
  
  <p>Example (I omit what's not important):</p>
  
  <p>Doc 1:</p>
  
  <pre><code>{
      'Field1': 'A perfect normal string'
  }
  </code></pre>
  
  <p>Doc N:</p>
  
  <pre><code>{ 
      'Field1': 'This one ends with my substring'
  }
  </code></pre>
  
  <p>The ideal will be:</p>
  
  <pre><code>$project: {
      'HasSubstring': {$cond: [{$regex: 'substring$'}, true, false]}
  }
  </code></pre>
  
  <p>But this doesn't work because we can't (????) use $regex inside a $cond</p>
  
  <p>Anyone could point me, please?</p>
  
  <p>Thanks a lot</p>
  
  <p>PS: I can't use the regex filter in the match because I need both docs for groupping them</p>