假设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. 复分析可视化方法:笔记:log(z)的可视化微分法

    当z转过θ时,我们来看看发生了什么: 左图中的空心箭头代表z的变化量,其长度为rδ,方向为pi/2+θ: 右图中的实心箭头代表log(z)的变化量,其长度为δ,方向为pi/2. 因此,从左图空心箭头到 ...

  2. 一款easyUI写的界面例子,小记

    后台是用strut2的: 前台界面风格easyUI,感觉挺好用的: <!DOCTYPE html> <html> <head> <meta charset=& ...

  3. java web中获取各种路径

    一.获取项目路径: 1) String path = request.getContextPath() :// /TestMyEclipseString basePath = request.getS ...

  4. [转]JSON.stringify 详解

    来自:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify J ...

  5. PLSQL导出表结构

    1:进行plsql后选怎Tools--------->Exports User Ojbects------------->选中需要导出的table,squence,view,type,fu ...

  6. eclipse离线安装Activiti Designer插件

    提供下载的链接:https://download.csdn.net/download/qq_41436774/10437391 1.打开Eclipse,点击Help ---> Install n ...

  7. Unreal Engine 4 笔记

    1.UE4的调试输出 //*1 调试输出*// /*case a.快速使用 不设置log类别 默认为LogTemp*/ UE_LOG(LogTemp,Log,TEXT("Your messa ...

  8. Linux系统查看系统硬件配置信息

    1.查看CPU信息 # 查看cpu负载 uptime # cpu使用率 (没有sar 则yum -y install sysstat) sar top bn1 |grep %Cpu # 每个cpu使用 ...

  9. extract 用法说明

    PHP extract() 函数从数组中把变量导入到当前的符号表中 定义和用法 PHP extract() 函数从数组中把变量导入到当前的符号表中. 对于数组中的每个元素,键名用于变量名,键值用于变量 ...

  10. NFS各个版本之间的比较

    NFS是一种网络文件系统,从1985年推出至今,共发布了3个版本:NFSv2.NFSv3.NFSv4,NFSv4包含两个次版本NFSv4.0和NFSv4.1.经过20多年发展,NFS发生了非常大的变化 ...