zoukankan      html  css  js  c++  java
  • MongoDB自定义函数部分 定义及引用

    1、

    //定义一个Sum的函数
    db.system.js.save({_id:"Sum",
                value:function(key,values)
                {
                    var total = 0;
                    for(var i =0;i <values.length;i++)
                        total += values[i];
                    return total;
                    }});

    2、

    //使用Sum函数
    db.loadServerScripts();Sum(1,[1,2,3,4,5,6,7,8,9])
    //在People集合中使用Sum函数
    db.people.runCommand(
    {
        mapreduce :"people",
        map:function(){
                emit(
                {key0:this.name,
                key1:this.created},
                this.phonenum
                );},
            reduce:function(key,values)
            {
                var result = Sum(key, values);
                return result;
                },
            out :{inline : 1 }});
  • 相关阅读:
    SQL Challenges靶机
    XSS靶机1
    djinn靶机
    Sunset靶机
    统计学 一 集中趋势
    测试
    测试
    统计学 一 集中趋势
    算法分析
    代码测试
  • 原文地址:https://www.cnblogs.com/liumengchen-boke/p/5863990.html
Copyright © 2011-2022 走看看