MongoDB - Use field in the document as regex expression

Viewed 20

I am storing regex expressions in MongoDB and would like to use them for queries.

Documents structure:

{
    "name": "foo",
    "regex_expression": "^[^@ ]+@(bar\\.com)$"
}

I tried the following query but it doesn't work.

db.collection.find({$expr: {$regex: ["foo@bar.com", "$regex_expression]}}) 

Is it possible to do this kind of query?

1 Answers
Related