Checking if a field contains a string
Checking if a field contains a string
You try this below example code:
db.users.findOne({"username" : {$regex : ".*son.*"}});
Regex support from mongo shell, that’s completely possible.
db.users.findOne({"username" : /.*son.*/});
If we need the query to be case-insensitive, we can use “i” option, like shown below:
db.users.findOne({"username" : /.*son.*/i});
Look this: http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-RegularExpressions
See: http://www.mongodb.org/display/DOCS/SQL+to+Mongo+Mapping+Chart
The MySQL
SELECT * FROM users WHERE username LIKE "%Son%"
The MongoDB
db.users.find({username:/Son/})