码迷,mamicode.com
首页 > 数据库 > 详细

mongodb Map/reduce测试代码

时间:2014-11-14 17:34:42      阅读:238      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   color   ar   sp   java   for   div   

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

        }

 

mongodb Map/reduce测试代码

标签:style   blog   io   color   ar   sp   java   for   div   

原文地址:http://www.cnblogs.com/zihunqingxin/p/4097622.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!