如何从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" } ] }热门推荐
1 狗狗技能训练
5 如何训练狗狗笑
6 狗狗训练排便
9 狗狗响片训练
10 如何训练狗狗不捡食
11 狗狗尿训练
12 怎么训练狗狗找东西
13 狗狗训练站立
14 狗狗训练飞盘
15 鞍山狗狗训练
16 怎样训练泰迪狗狗谢谢
17 狗狗外出训练
18 怎么训练金毛狗狗大小便