[SERVER-8892] Use $regex as the expression in a $cond Created: 07/Mar/13  Updated: 25/Jun/15  Resolved: 20/May/15

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: 2.2.0
Fix Version/s: None

Type: Improvement Priority: Trivial - P5
Reporter: Garito Assignee: Unassigned
Resolution: Duplicate Votes: 3
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-11947 Add a regex expression to the aggrega... Closed
Related
related to SERVER-8582 Extend document expression language i... Closed
Participants:

 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


Generated at Thu Feb 08 03:18:45 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.