在MongoDB中查询多个参数?
要在MongoDB中查询多个参数,可以使用dot(。)表示法。首先让我们创建一个包含文档的集合-
> db.multipleParametersDemo.insertOne(
... {
... "CustomerName" : "Larry",
... "CustomerDetails" : [
... {
... "CustomerCountryName" : "US",
... "CustomerBankName" : "HDFC",
... "CustomerBalance" : 17363,
... }
... ],
... "Purchase" : 1456,
...
... }
... );
{
"acknowledged" : true,
"insertedId" : ObjectId("5cd10f9ce3526dbddbbfb60a")
}以下是在find()方法的帮助下显示集合中所有文档的查询-
> db.multipleParametersDemo.find().pretty();
这将产生以下输出-
{
"_id" : ObjectId("5cd10f9ce3526dbddbbfb60a"),
"CustomerName" : "Larry",
"CustomerDetails" : [
{
"CustomerCountryName" : "US",
"CustomerBankName" : "HDFC",
"CustomerBalance" : 17363
}
],
"Purchase" : 1456
}以下是如何在MongoDB中查询多个参数-
> db.multipleParametersDemo.find({CustomerName: 'Larry', 'CustomerDetails.CustomerCountryName': 'US'}).count();这将产生以下输出-
1
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短