Use $regex as the expression in a $cond

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Duplicate
    • Priority: Trivial - P5
    • None
    • Affects Version/s: 2.2.0
    • Component/s: Aggregation Framework
    • None
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Pre requisites:
      The regex returns a boolean

      Should be trivial to make it work as the expression in a $cond while projecting

      Example:
      Schema:

      {
        '_id': IDObject,
        'Path': string,
        '...': a bunch of other fields
      }
      

      Aggregation command:

      {
        '$match': { ... }
      },
      {
        '$project': {
          '_id': '$_id',
          'EndsWithString': {
            '$cond': [
              {'$Path': {'$regex': 'String$'}}, # This is the same notation that for find or find_one. It should return true/false
              true,
              false
            ]
          }
        }
      }
      

      PS: I very influenced by the pymongo driver so excuse me if I mix console and python notation. Trying to ilustrate the point

              Assignee:
              Unassigned
              Reporter:
              Garito
              Votes:
              3 Vote for this issue
              Watchers:
              11 Start watching this issue

                Created:
                Updated:
                Resolved: