db.bug.insert({tag: "foo", date:ISODate("2012-02-09T08:39:20Z")});
|
db.bug.insert({tag: "bar", date:ISODate("2012-02-09T08:39:20Z")});
|
m = function(){emit(this.tag,this)};
|
r = function(k,v){return v[0]};
|
f = function(k,v){v.date.setUTCHours(0);return v;}
|
|
// bug: finalize output is not used, dates still have non-zero hours.
|
db.bug.mapReduce(m, r, {"out":{inline:1}, "finalize":f});
|
|
// workaround: make trivial change to finalize output so that m/r framework picks up the change:
|
f = function(k,v){v.date.setUTCHours(0); v.x = 1; return v;}
|
db.bug.mapReduce(m, r, {"out":{inline:1}, "finalize":f});
|
The results from the first MR:
"results" : [
|
{
|
"_id" : "bar",
|
"value" : {
|
"_id" : ObjectId("4f338638400b97e04a51941e"),
|
"tag" : "bar",
|
"date" : ISODate("2012-02-09T08:39:20.396Z")
|
}
|
},
|
{
|
"_id" : "foo",
|
"value" : {
|
"_id" : ObjectId("4f338631400b97e04a51941d"),
|
"tag" : "foo",
|
"date" : ISODate("2012-02-09T08:39:13.820Z")
|
}
|
}
|
],
|
The results from the second MR:
"results" : [
|
{
|
"_id" : "bar",
|
"value" : {
|
"_id" : ObjectId("4f338638400b97e04a51941e"),
|
"tag" : "bar",
|
"date" : ISODate("2012-02-09T00:39:20.396Z"),
|
"x" : 1
|
}
|
},
|
{
|
"_id" : "foo",
|
"value" : {
|
"_id" : ObjectId("4f338631400b97e04a51941d"),
|
"tag" : "foo",
|
"date" : ISODate("2012-02-09T00:39:13.820Z"),
|
"x" : 1
|
}
|
}
|
],
|
|