Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongodb dynamic like operator

In mongodb the equivalent to sql "like" operator is

db.users.find({"shows": /m/})

Using nodejs/javascript I want to dynamically change letter, based on url paramater.

I have tried

letter = req.params.letter;

db.users.find({"shows": '/' + letter + '/'})

This doesn't work, I guess because the slashes are now strings are interpreted differently.

like image 536
jamjam Avatar asked Jul 06 '12 12:07

jamjam


1 Answers

One way to do it, according to the documentation page:

db.users.find( { shows : { $regex : letter } } );
like image 69
mindandmedia Avatar answered Sep 22 '22 12:09

mindandmedia