Skip to content

Instantly share code, notes, and snippets.

@tomysmile
Created October 17, 2015 12:42
Show Gist options
  • Save tomysmile/42cc7cdb501058bfc867 to your computer and use it in GitHub Desktop.
Save tomysmile/42cc7cdb501058bfc867 to your computer and use it in GitHub Desktop.
mongo: query like
db.users.insert({name: 'paulo'})
db.users.insert({name: 'patric'})
db.users.insert({name: 'pedro'})
db.users.find({name: /a/})  //like '%a%'

out: paulo, patric

db.users.find({name: /^pa/}) //like 'pa%' 

out: paulo, patric

db.users.find({name: /ro$/}) //like '%ro'

out: pedro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment