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