Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-4916

finalize output is ignored unless top-level property is changed

    • Query Optimization
    • ALL

      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
      			}
      		}
      	],
      

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            keeth Keith Grennan
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: