DEV Community

Theo
Theo

Posted on

MongoDB equivalent of SQL LIKE query

A quick snippet for anyone looking for equivalent SQL LIKE queries for mongodb.

db.users.find({name: /a/}) 
SELECT * FROM USERS WHERE name LIKE '%a%';

db.users.find({name: /^ja/}) 
SELECT * FROM USERS WHERE name LIKE 'ja%'

db.users.find({name: /jo$/}) 
SELECT * FROM USERS WHERE name LIKE '%jo'
Enter fullscreen mode Exit fullscreen mode

Top comments (0)