假设students集合中有这样的数据:

{
"_id" : 1,
"name" : "Aurelia Menendez",
"scores" : [
{
"type" : "exam",
"score" : 60.06045071030959
},
{
"type" : "quiz",
"score" : 52.79790691903873
},
{
"type" : "homework",
"score" : 71.76133439165544
},
{
"type" : "homework",
"score" : 34.85718117893772
}
]
},
{
"_id" : 3,
"name" : "Bao Ziglar",
"scores" : [
{
"type" : "exam",
"score" : 71.64343899778332
},
{
"type" : "quiz",
"score" : 24.80221293650313
},
{
"type" : "homework",
"score" : 1.694720653897219
},
{
"type" : "homework",
"score" : 42.26147058804812
}
]
},
{
"_id" : 2,
"name" : "Corliss Zuk",
"scores" : [
{
"type" : "exam",
"score" : 67.03077096065002
},
{
"type" : "quiz",
"score" : 6.301851677835235
},
{
"type" : "homework",
"score" : 20.18160621941858
},
{
"type" : "homework",
"score" : 66.28344683278382
}
]
}

需要找出每个学生成绩最小值,可使用如下语句:

db.students.aggregate([{$project: {minScore: {$min: "$scores.score"}}}])

语句里面的minScore等于是一个别名,可以使用其它的。结果如下:

{ "_id" : 1, "minScore" : 34.85718117893772 }
{ "_id" : 3, "minScore" : 1.694720653897219 }
{ "_id" : 2, "minScore" : 6.301851677835235 }
{ "_id" : 4, "minScore" : 19.21886443577987 }
{ "_id" : 5, "minScore" : 10.53058536508186 }
{ "_id" : 7, "minScore" : 42.48780666956811 }
{ "_id" : 6, "minScore" : 16.58341639738951 }
{ "_id" : 8, "minScore" : 14.63969941335069 }
{ "_id" : 9, "minScore" : 12.47568017314781 }
{ "_id" : 0, "minScore" : 1.463179736705023 }
{ "_id" : 12, "minScore" : 14.78936520432093 }
{ "_id" : 13, "minScore" : 78.18795058912879 }
{ "_id" : 14, "minScore" : 13.66179556675781 }
{ "_id" : 11, "minScore" : 15.81264595052612 }
{ "_id" : 16, "minScore" : 7.772386442858281 }
{ "_id" : 15, "minScore" : 3.311794422000724 }
{ "_id" : 18, "minScore" : 62.12870233109035 }
{ "_id" : 17, "minScore" : 31.15090466987088 }
{ "_id" : 10, "minScore" : 19.31113429145131 }
{ "_id" : 19, "minScore" : 0.6578497966368002 }

mongodb根据子项中的指标查找最小或最大值的更多相关文章

  1. POJ 3273 Monthly Expense二分查找[最小化最大值问题]

    POJ 3273 Monthly Expense二分查找(最大值最小化问题) 题目:Monthly Expense Description Farmer John is an astounding a ...

  2. 【Python实践-5】使用迭代查找一个list中最小和最大值

    # -*- coding: utf-8 -*- #使用迭代查找一个list中最小和最大值,并返回一个tuple #遍历list,找到最小值 def findMinAndMax(L): if L==[] ...

  3. 请使用迭代查找一个list中最小和最大值,并返回一个tuple

    如果给定一个list或tuple,我们可以通过for循环来遍历这个list或tuple,这种遍历我们称为迭代(Iteration). 在Python中,迭代是通过for ... in来完成的,而很多语 ...

  4. python 练习题:使用迭代查找一个list中最小和最大值,并返回一个tuple

    # -*- coding: utf-8 -*- # 请使用迭代查找一个list中最小和最大值,并返回一个tuple from collections import Iterable def findM ...

  5. 原创:从海量数据中查找出前k个最小或最大值的算法(java)

    现在有这么一道题目:要求从多个的数据中查找出前K个最小或最大值 分析:有多种方案可以实现.一.最容易想到的是先对数据快速排序,然后输出前k个数字.   二.先定义容量为k的数组,从源数据中取出前k个填 ...

  6. python 请使用迭代查找一个list中最小和最大值,并返回一个tuple

    请使用迭代查找一个list中最小和最大值,并返回一个tuple: 要注意返回的值的类型是不是tuple def findMinAndMax(L): min=0 max=0 if len(L)==0: ...

  7. 【编程题目】查找最小的 k 个元素

    5.查找最小的 k 个元素(数组)题目:输入 n 个整数,输出其中最小的 k 个.例如输入 1,2,3,4,5,6,7 和 8 这 8 个数字,则最小的 4 个数字为 1,2,3 和 4. 算法里面学 ...

  8. sql查找最小缺失值与重用被删除的键(转载)

    转载自:http://blog.csdn.net/yanghua_kobe/article/details/6262550 在数据处理时,我们经常会使用一些“自增”的插入方式来处理数据.比如学生学号: ...

  9. Oracle Statspack报告中各项指标含义详解~~学习性能必看!!!

    Oracle Statspack报告中各项指标含义详解~~学习性能必看!!! Data Buffer Hit Ratio#<#90# 数据块在数据缓冲区中的命中率,通常应该在90%以上,否则考虑 ...

随机推荐

  1. 如何手动关闭tomcat服务,不在Eclipse中的server里按那个红色按钮关

    首先,找到Tomcat服务器的安装目录bin目录下的shutdown.bat.然后拖动到命令行进行操作,将Tomcat服务器关闭~ 将shutdown.bat 文件拖至命令行操作当中,执行该命令,即可 ...

  2. 关于后台程序java报错问题解决

    HTTP Status – Internal Server Error Type Exception Report Message Handler processing failed; nested ...

  3. springMVC学习(3)-springMVC和mybatis整合

    一.需求:使用springmvc和mybatis完成商品列表查询. 二.整合思路:springMVC+mybaits的系统架构: 1步):整合dao层 mybatis和spring整合,通过sprin ...

  4. RDD之七:Spark容错机制

    引入 一般来说,分布式数据集的容错性有两种方式:数据检查点和记录数据的更新. 面向大规模数据分析,数据检查点操作成本很高,需要通过数据中心的网络连接在机器之间复制庞大的数据集,而网络带宽往往比内存带宽 ...

  5. css属性所对应js属性

    document.getElementById("xx").style.xxx中的所有属性是什么,css对应js: 盒子标签和属性对照 CSS语法(不区分大小写) JavaScri ...

  6. Program.cs 累积_C#

    using System; using System.Diagnostics; using System.Threading; using System.Windows.Forms; using Ut ...

  7. python selenium-2 定位元素

    元素 方法 示例 id find_element_by_id('su') driver.get("http://www.baidu.com")driver.find_element ...

  8. java-appium-527手机浏览器、PC端程序、grid模式

    1.手机浏览器 2.window通用成语自动化 3.appium支持grid模式

  9. VM虚拟机占内存非常大

    我发现每次打开虚拟机占用内存非常大,经常会卡死,后来上网找原因,发现内存设置的问题,所以我就修改了虚拟机的内存,网上说如果是win7,内存设置需要1-2G,如果是xp,512M就够了. 经测试,内存还 ...

  10. ni_set()函数的使用 以及 post_max_size,upload_max_filesize的修改方法

    Apache服务器处理: ini_set('display_errors', 'Off');ini_set('memory_limit', -1); //-1 / 10240Mini_set(&quo ...