- In the find() method if we pass multiple keys by separating them by ',' then MongoDB treats it as AND condition.
db.collection.find({key1:value1, key2:value2}).pretty()
> db.wikitechy4.find({"author":"jln"}).pretty()
{
"_id" : ObjectId("5731e2eadaa4a0bc932a2ffb"),
"websitename" : "www.wikitechy.com",
"details" : "next row inserted",
"articlecount" : "40",
"author" : "jln"
}
{
"_id" : ObjectId("5731f734daa4a0bc932a2ffd"),
"websitename" : "www.wikitechy.com",
"details" : "last row inserted",
"articlecount" : "40",
"author" : "jln"
}
{
"_id" : ObjectId("5731f73fdaa4a0bc932a2ffe"),
"websitename" : "www.wikitechy.com",
"details" : "last row inserted",
"articlecount" : "50",
"author" : "jln"
}
> db.wikitechy4.find({"author":"jln","articlecount":"50"}).pretty()
{
"_id" : ObjectId("5731f73fdaa4a0bc932a2ffe"),
"websitename" : "www.wikitechy.com",
"details" : "last row inserted",
"articlecount" : "50",
"author" : "jln"
}
>
- Here in this output, we display the 3 rows of data’s from the collection “wikitechy4” where only the author name as “jln” tends to display that data using find() rich query.
- Over here in this output, we display the data from the collection “wikitechy4” where only the author name as “jln” & the article count as “50” constrain data’s will be displayed using find() rich query.