$cond
in mongodb is defined like this:
$cond: { if: { $gte: [ "$qty", 250 ] }, then: 30, else: 20 }
But, can we do that for a string ? I want to compare string value inside a document with regex, so something like this can work:
$cond: { if: { $match: [/sam/, "$name"] }, then: 30, else: 20 }
/sam/
is a regular expression and "$name"
is the field that I want to compare to. As a side note, this expression will be put in the aggregate pipeline.