MongoDb : mapReduce out collection result

瘦欲@ 提交于 2019-12-11 10:46:54

问题


I have the below Logincount.js .

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

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

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

This is my js file

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

回答1:


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?



来源:https://stackoverflow.com/questions/16322178/mongodb-mapreduce-out-collection-result

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!