select(find) query with like operator in MongoDB

select(find) query with like operator in MongoDB

select * from employees

> db.employees.find( {},{_id:0})
{ “name” : “abc123”, “age” : 55, “status” : “A” }
{ “name” : “qwe”, “age” : 20, “status” : “A” }
{ “name” : “zxc”, “age” : 25, “status” : “A” }
{ “name” : “asd”, “age” : 35, “status” : “A” }
{ “name” : “kkk”, “age” : 23, “status” : “N” }

select * from employees where name like ‘ab%’;

It work as regular expression syntax: /pattern/

db.employees.find( { name: /^ab.*/ } )

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s