zoukankan      html  css  js  c++  java
  • mongo学习- mapReduce操作事例

    源数据:

    {
        "_id" : 1.0,
        "name" : "abc",
        "age" : 43.0,
        "type" : 1.0,
        "status" : "P",
        "favorites" : {
            "artist" : "Picasso",
            "food" : "pizza"
        },
        "finished" : [ 
            17.0, 
            3.0
        ],
        "badges" : [ 
            "blue", 
            "black"
        ],
        "points" : [ 
            {
                "points" : 85.0,
                "bonus" : 20.0
            }, 
            {
                "points" : 85.0,
                "bonus" : 10.0
            }
        ]
    }
    
    /* 2 */
    {
        "_id" : 2.0,
        "name" : "abc",
        "age" : 42.0,
        "type" : 1.0,
        "status" : "A",
        "favorites" : {
            "artist" : "Miro",
            "food" : "meringue"
        },
        "finished" : [ 
            11.0, 
            25.0
        ],
        "badges" : [ 
            "green"
        ],
        "points" : [ 
            {
                "points" : 85.0,
                "bonus" : 20.0
            }, 
            {
                "points" : 64.0,
                "bonus" : 12.0
            }
        ]
    }
    
    /* 3 */
    {
        "_id" : 3.0,
        "name" : "ahn",
        "age" : 43.0,
        "type" : 2.0,
        "status" : "A",
        "favorites" : {
            "artist" : "Cassatt",
            "food" : "cake"
        },
        "finished" : [ 
            6.0
        ],
        "badges" : [ 
            "blue", 
            "red"
        ],
        "points" : [ 
            {
                "points" : 81.0,
                "bonus" : 8.0
            }, 
            {
                "points" : 55.0,
                "bonus" : 20.0
            }
        ]
    }
    
    /* 4 */
    {
        "_id" : 4.0,
        "name" : "xi",
        "age" : 34.0,
        "type" : 2.0,
        "status" : "D",
        "favorites" : {
            "artist" : "Chagall",
            "food" : "chocolate"
        },
        "finished" : [ 
            5.0, 
            11.0
        ],
        "badges" : [ 
            "red", 
            "black"
        ],
        "points" : [ 
            {
                "points" : 53.0,
                "bonus" : 15.0
            }, 
            {
                "points" : 51.0,
                "bonus" : 15.0
            }
        ]
    }
    
    /* 5 */
    {
        "_id" : 5.0,
        "name" : "xyz",
        "age" : 23.0,
        "type" : 2.0,
        "status" : "D",
        "favorites" : {
            "artist" : "Noguchi",
            "food" : "nougat"
        },
        "finished" : [ 
            14.0, 
            6.0
        ],
        "badges" : [ 
            "orange"
        ],
        "points" : [ 
            {
                "points" : 71.0,
                "bonus" : 20.0
            }
        ]
    }
    
    /* 6 */
    {
        "_id" : 6.0,
        "name" : "abc",
        "age" : 43.0,
        "type" : 1.0,
        "status" : "A",
        "favorites" : {
            "food" : "pizza",
            "artist" : "Picasso"
        },
        "finished" : [ 
            18.0, 
            12.0
        ],
        "badges" : [ 
            "black", 
            "blue"
        ],
        "points" : [ 
            {
                "points" : 78.0,
                "bonus" : 8.0
            }, 
            {
                "points" : 57.0,
                "bonus" : 7.0
            }
        ]
    }
    

      

    var mrr=db.users.mapReduce(
    function(){
    emit(this.age,this.name);
    },
    function(key,values){
    var a=Avalues.length;

    var ret={age:key,names:a};
    return ret;
    },
    { out: {replace:"result"}}

    );
    db[mrr.result].find()

  • 相关阅读:
    谈谈分布式事务之一:SOA需要怎样的事务控制方式
    asp.net创建自定义排序用户界面
    在ASP.NET 2.0中操作数据:在GridView的页脚中显示统计信息
    Url重写技术的运用(转)
    ASP.NET 对 SqlDataSource 控件使用参数
    正则表达式分支条件与分组
    向DWR传递参数和返回参数(转)
    一位软件工程师的6年总结(转)
    ASP.NET 2.0数据教程之二十六::排序自定义分页数据
    Table控件使用示例
  • 原文地址:https://www.cnblogs.com/anxbb/p/9475640.html
Copyright © 2011-2022 走看看