Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-8892

Use $regex as the expression in a $cond

    • Type: Icon: Improvement Improvement
    • Resolution: Duplicate
    • Priority: Icon: Trivial - P5 Trivial - P5
    • None
    • Affects Version/s: 2.2.0
    • Component/s: Aggregation Framework
    • 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 Unassigned
            Reporter:
            garito Garito
            Votes:
            3 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved: