MongoDb:mapReduce收集结果 [英] MongoDb : mapReduce out collection result

查看:89
本文介绍了MongoDb:mapReduce收集结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的Logincount.js.

I have the below Logincount.js .

请告诉我在创建集合LoginCount时如何也包括日期字段?

Please tell me how can i Include the Date Field also while creating the collection LoginCount ??

现在js文件创建了一个具有两个字段的集合,即_id和value

Right now the js file creates a collection with two fields namely _id and value

我希望它还创建一个名为date的字段,其中包含昨天的Date.

I want it to also create a field called date with yesterdays Date in it .

这是我的js文件

m = function() { emit(this.cust_id, 1); }

r = function (k, vals) { var sum = 0; for (var i in vals) { sum += vals[i]; } return sum; }

   q = function() {
        var currentDate = new Date();
        currentDate.setDate(currentDate.getDate()-1);
        var month = (currentDate.getMonth() < 9 ? "0"+ (currentDate.getMonth()+1) : (currentDate.getMonth()+1));
        var day = (currentDate.getDate() < 10 ? "0" + currentDate.getDate() : currentDate.getDate());
        var date = currentDate.getTime();
        var patt = date;
        var query = {"created_at":patt};
        return query;
}


res = db.user_logins.mapReduce(m, r, { query : q(), out :  "LoginCount" });

推荐答案

据我所知,MapReduce生成的集合中可以包含的 only 字段是_id和value. MapReduce的性质.也许您可以对输出集合进行更新以拉平"值字段?

As far as I know, the only fields you can have in a collection generated by MapReduce are _id and value – this is just the nature of MapReduce. Maybe you could run an update on your output collection that "flattens" the value field?

这篇关于MongoDb:mapReduce收集结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆