MongoDB reverse regex
Solution 1:
You can use the $where operator in the following fashion:
db.col.find({$where: "\"my regex\".match(this.regex)"})
Solution 2:
As explained into Jira ticket provided by @fgalan on 2013, you can use $expr
you can use this query:
db.collection.find({
"$expr": {
"$regexMatch": {
"input": "$key",
"regex": "$regex",
"options": "i"
}
}
})
Example here
With $expr
you can avoid $where
which is not efficient.