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;
            }

        }

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。