select(find) query with where condition in MongoDB

select(find) query with where condition in MongoDB

> 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” }

Equal to
————
select * from employees where status = ‘A’;

db.employees.find( {status: “A”} )

> db.employees.find( {status:”A”},{_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” }

Not equal to
————–
select * from employees where status != ‘A’;

db.employees.find( { status: { $ne: “A” } } )

> db.employees.find( { status: { $ne: “A” } }, {_id:0})
{ “name” : “kkk”, “age” : 23, “status” : “N” }

equal and greater then
————————
SELECT * FROM employees WHERE age >= 25

db.employees.find(  { status: “A”,age:{$gte:35} } )

> db.employees.find(  { status: “A”,age:{$gte:35} }, {_id:0})
{ “name” : “abc123”, “age” : 55, “status” : “A” }
{ “name” : “asd”, “age” : 35, “status” : “A” }
>

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.