网站答辩ppt怎么做,博客程序seo,南宁网站建设是什么意思,陕西省建设监理协会证书查询网站文章目录 语法使用 举例 MongoDB聚合运算符#xff1a; p o w ‘ pow pow‘pow聚合运算符用于求数字指定的指数并返回结果。 语法
{ $pow: [ number, exponent ] }参数说明#xff1a;
number表达式可以是任何可解析为数值的表达式exponent p o w ‘ pow pow‘pow聚合运算符用于求数字指定的指数并返回结果。 语法
{ $pow: [ number, exponent ] }参数说明
number表达式可以是任何可解析为数值的表达式exponent表达式可以是任何能够解析为数值的表达式零的指数不能是负值
使用
结果与输入类型相同除非无法以该类型准确表示。在这些情况下
如果结果可表示为64位整数则32位整数将转换为 64 位整数。如果结果无法表示为64位整数则32位整数将转换为双精度型。如果结果不能表示为64位整数则64位整数将转换为double。
如果任一参数解析为null值或引用缺少的字段则$pow返回null。如果任一参数解析为NaN则$pow返回NaN。
例子结果{ $pow: [ 5, 0 ] }1{ $pow: [ 5, 2 ] }25{ $pow: [ 5, -2 ] }0.04{ $pow: [ -5, 0.5 ] }NaN
举例
使用下面的脚本创建quizzes集合
db.quizzes.insertMany( [{_id : 1,scores : [{ name : dave123, score : 85 },{ name : dave2, score : 90 },{ name : ahn, score : 71 }]},{_id : 2,scores : [{ name : li, quiz : 2, score : 96 },{ name : annT, score : 77 },{ name : ty, score : 82 }]}
] )以下示例计算每个quiz的方差
db.quizzes.aggregate( [{ $project: { variance: { $pow: [ { $stdDevPop: $scores.score }, 2 ] } } }
] )操作返回下面的结果
{ _id : 1, variance : 64.66666666666667 }
{ _id : 2, variance : 64.66666666666667 }