如何从MongoDB中的嵌入式列表中获取大于特定值的值?
要获得大于特定值的值,请将$gt与一起使用find()。让我们创建一个包含文档的集合-
> db.demo317.insertOne(
... {'id':101,
... 'details':[{'Score':78,Name:"Chris"},
... {'Score':88,Name:"David"}
... ]
... }
... );
{
"acknowledged" : true,
"insertedId" : ObjectId("5e50e69cf8647eb59e562060")
}
> db.demo317.insertOne(
... {'id':102,
... 'details':[{'Score':90,Name:"Chris"},
... {'Score':91,Name:"David"}
... ]
... }
... );
{
"acknowledged" : true,
"insertedId" : ObjectId("5e50e6adf8647eb59e562061")
}在find()方法的帮助下显示集合中的所有文档-
> db.demo317.find();
这将产生以下输出-
{ "_id" : ObjectId("5e50e69cf8647eb59e562060"), "id" : 101, "details" : [ { "Score" : 78, "Name" : "Chris" }, { "Score" : 88, "Name" : "David" } ] }
{ "_id" : ObjectId("5e50e6adf8647eb59e562061"), "id" : 102, "details" : [ { "Score" : 90, "Name" : "Chris" }, { "Score" : 91, "Name" : "David" } ] }以下是在MongoDB的嵌入式列表中使用$gt来获取大于89的得分记录的查询-
> db.demo317.find({"details.Score" :{"$gt": 89}});这将产生以下输出-
{ "_id" : ObjectId("5e50e6adf8647eb59e562061"), "id" : 102, "details" : [ { "Score" : 90, "Name" : "Chris" }, { "Score" : 91, "Name" : "David" } ] }热门推荐
10 病人祝福语老师寄语简短
11 新娘生孩子祝福语简短
12 婆婆66岁祝福语简短
13 今天孩子高考祝福语简短
14 送彩票生日祝福语简短
15 分别祝福语简短情话英文
16 画室揭牌仪式祝福语简短
17 女友妈妈生日祝福语简短
18 离别赠言离职祝福语简短