如何从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 撩妹生日祝福语简短
13 给儿子生日祝福语 简短
14 白羊生日祝福语 简短独特
15 给老板祝福语简短精辟
16 毕业结婚祝福语简短精辟
17 60岁长辈祝福语简短
18 朋友明天手术祝福语简短