Reputation: 3
I am a newbie to mongodb. I just want to know what is the Mongodb equivalent operator for mysql _ for wildcard search. For example in mysql if want to search a phone number column in the format of 123 456 7890 we can search like '_ _ ____'. How do we search it in mongodb
Upvotes: 0
Views: 1725
Reputation: 518
If in MySql you might have a query with a wildcard like this:
mysql> SELECT * FROM pets WHERE name LIKE '_____';
In Mongo, you can use regex syntax, like:
db.pets.find( { name: { $regex: /[a-zA-Z]{5}/ } } );
If you can write regex for what you want, then you can query in this way.
There are some expressions for things like phone numbers here: http://www.regexlib.com/Search.aspx?k=phone&AspxAutoDetectCookieSupport=1
Upvotes: 1