In SQL it is possible to run a query similar to
SELECT result FROM table WHERE 'abc-def-ghi' LIKE col1
on a table like this:
col1 | result
abc-% | 1
abc-d% | 2
as% | 3
... | ...
and get a result set with 1 and 2.
Problem: how do I achieve same effect in mongodb? I can run regex to match against fields but is there a way that the fields could be match agains supplied data?
You can use the $where operator, e.g.:
db.col.find({$where: "\"abc\".match(this.col1)"})
Although MongoDB documentation doesn't recommend using $where, it is the only possibility as far as I know.
(This question is probably a duplicate. See MongoDB reverse regex)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With