首页 > 代码库 > 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测试代码
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。