MongoDB equivalent of SQL LIKE query

tios

Theo

Posted on September 1, 2021

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
💖 💪 🙅 🚩
tios
Theo

Posted on September 1, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

MongoDB equivalent of SQL LIKE query
mongodb MongoDB equivalent of SQL LIKE query

September 1, 2021