Mongo Query with Regex in Node JS operating ON A VARIABLE Mongo Query with Regex in Node JS operating ON A VARIABLE mongodb mongodb

Mongo Query with Regex in Node JS operating ON A VARIABLE


Try this one:

db.testlogwiki.find({"line_text" : new RegExp(result) };


Both will work

db.testlogwiki.find({"line_text" : new RegExp(result, 'i') }; // to make this case insensitive 

or

db.testlogwiki.find( { line_text: { $regex: result[, $options: 'i'] } } );


You can also use the $regex option.

db.testlogwiki.find( { line_text: { $regex: result[, $options: 'i'] } } );