node.js - How can I search a MongoDB of regexes for matches against a given string? -


i have mongo database accessing via mongoose , node.js. database contains series of items called machine. each machine has field stored string, represents regular expression. want take given string (provided user) , check against regular expressions in database find potential matches. know can search database via regex this:

machines.find({subject: {$regex: hi}}).exec(function(err, results) {     // stuff results }); 

but how can reverse of this?

you can using $where:

machines.find({     $where: 'new regexp(this.subject).test(' + '"' + string + '") === true' }) 

also hi greg


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -