Reputation: 32321
I have a Collection named as Orders in my Mongo DB .
Is it possible to do a search on mongo DB based on two fileds .
For example i want to search the collection based on symbol and hi
db.Orders.find({"symbol" : "AADI"})
Please let me know how can i include the other parameter hi also in the search ??
Thanks
Upvotes: 1
Views: 14560
Reputation: 1718
Also, once you use:
db.users.find(
{ status: "A",
age: 50 }).pretty()
Using pretty()
method at the end of the statement, you make sure that the info comes with a \n
per key : value
Upvotes: 0
Reputation: 2984
Mongodb provides an implicit AND
, so when you do
db.inventory.find( { price: 1.99, qty: { $lt: 20 } , sale: true } )
it is same as
db.inventory.find({ $and: [ { price: 1.99 }, { qty: { $lt: 20 } }, { sale: true } ] } )
For other operators you can have a look at the reference
mixing $or with logical AND
db.inventory.find( { price:1.99, $or: [ { qty: { $lt: 20 } }, { sale: true } ] } )
This query will select all documents in the inventory collection where:
the price field value equals 1.99 and either the qty field value is less than 20 or the sale field value is true.
Other operators
You can refer to the reference for examples to other operators.
Upvotes: 2
Reputation: 13059
Just have two conditions separated by commas:
e.g.
db.users.find(
{ status: "A",
age: 50 }
)
http://docs.mongodb.org/manual/reference/sql-comparison/
Upvotes: 10