Dùng ký pháp chấm (dot notation) để truy vấn field lồng nhau. Tạo collection:
> db.multipleParametersDemo.insertOne(
{
"CustomerName" : "Larry",
"CustomerDetails" : [
{ "CustomerCountryName" : "US", "CustomerBankName" : "HDFC", "CustomerBalance" : 17363 }
],
"Purchase" : 1456
}
);
{ "acknowledged" : true, "insertedId" : ObjectId("5cd10f9ce3526dbddbbfb60a") }
Hiển thị document:
> db.multipleParametersDemo.find().pretty();
Kết quả:
Truy vấn nhiều tham số: CustomerName = 'Larry' VÀ CustomerDetails.CustomerCountryName = 'US':
> db.multipleParametersDemo.find({CustomerName: 'Larry', 'CustomerDetails.CustomerCountryName': 'US'}).count();Kết quả:
1.