首页 > 代码库 > mongodb Map/reduce测试代码

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

 

mongodb Map/reduce测试代码