zoukankan      html  css  js  c++  java
  • mongodb Map/reduce测试代码

      private void AccountInfo()
            {
                ls.Clear();
                DateTime dt = DateTime.Now.Date;
                IMongoQuery query = Query<mtime_time>.GTE(p => p.showdate, dt);
                MapReduceOutput output = new MapReduceOutput("mtime_time_tem");
    
                MongoCollection comcol = MongoFactory.GetMongoCollction("entBoxOffice", "mtime_time_tem");
    
    
                string mapjs = @"function () {
        var result = {};
        //总场次
        var count = 0;
        //有人场次
        var haspersoncount = 0;
        //入库场次
        var hasin = 0;
        //入库总人次
        var inpersoncount = 0;
        //总人次
        var personcount = 0;
            count = 1;
            if (this.sold > 0) {
                haspersoncount = 1;
                personcount = this.sold;
                if (this.Sqlsta == 1) {
                    inpersoncount = this.sold;
                }
            }
            if (this.Sqlsta == 1) {
                hasin = 1;
            }
        result.count = count;
        result.haspersoncount = haspersoncount;
        result.hasin = hasin;
        result.inpersoncount = inpersoncount;
        result.personcount = personcount;
    emit(this.movieid, result);
       
    }";
                string reducejs = @"function (key, values) {
        var result = {};
          result.count = 0;
            result.haspersoncount =0;
            result.hasin = 0;
            result.inpersoncount = 0;
            result.personcount = 0;
       values.forEach(function (value) {
            result.count += value.count;
            result.haspersoncount += value.haspersoncount;
            result.hasin += value.hasin;
            result.inpersoncount += value.inpersoncount;
            result.personcount += value.personcount;
        });
        return result;
    }";
               
    
                try
                {
    
    
                    var options = new MapReduceOptionsBuilder().SetQuery(query).SetOutput(output);
                    var map = new BsonJavaScript(mapjs);
                    var reduce = new BsonJavaScript(reducejs);
                    var obj = mtime_timeDAL.collection.MapReduce(map,
                     reduce, options
                    );
                    List<BsonDocument> doc = obj.GetResults().ToList();
    
                    //List<moveibase> 
    
                    //jinyi_timeDAL.collectionmovie
    
    
    
                    GetDocAddLs(doc, "时光网");
                    comcol.Drop();
                    map = new BsonJavaScript(mapjs.Replace("movieid", "filmId"));
    
    
                    obj = wd_timeDAL.collection.MapReduce(map,
                 reduce, options
                );
                    doc = obj.GetResults().ToList();
    
                }
                catch (Exception ex)
                {
    
                    throw;
                }
    
            }
  • 相关阅读:
    【转】揭秘令牌桶
    各空白字符说明
    【转】Python正则表达式指南
    python的urlparse
    【转】HTTP Header 详解
    ElasticSearch(六)底层索引控制
    ElasticeSearch(五)分布式索引架构
    Elasticsearch(四)优化用户体验
    ElasticSearch(三)不仅仅是查询
    ElasticSearch(二) 关于DSL
  • 原文地址:https://www.cnblogs.com/zihunqingxin/p/4097622.html
Copyright © 2011-2022 走看看