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

Use $regex as the expression in a $cond

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Trivial - P5
    • Resolution: Duplicate
    • Affects Version/s: 2.2.0
    • Fix Version/s: None
    • Component/s: Aggregation Framework
    • Labels:
      None

      Description

      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

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved: