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
Post a Comment