Wednesday, 15 February 2012

mapreduce - Mongodb map reduce result format changes -


I am using Java API and call the following map command:

  MAP function () {emit ('nogroup', {endtime: this.endtime, _owner: this._owner}); } Reduce the Reduce function (key, value) {var res = 3426533531976; (Var i = 0; i & lt; values.length; i ++) {if (value [i] .endtime & lt; res and value [i] ._man == faucet) res = value [i ] .endtime; } Return Ridge; }  

with this code

  string map = "function () {emit ('nogroup', {endtime: this.endtime, _owner: this ). _owner}); }"; Reduce string = "Reduce function (key, value) for {var res = 9426533531976; (var i = 0; i & lt; values.length; i ++) {if (value [i] .endtime & lt ; Res & amp; amp; and value [i] ._man == faucet) res = value [i] .endtime;} return ridge;} "; MapReduceCommand CMD = New MapReduceCommand (userdataCollection, map, less, blank, MapReduceCommand.OutputType.INLINE, blank); MapReduceOutput Out = userdataCollection.mapReduce (cmd);  

Sometimes results appear

  {"_id": "nogroup", "value": {"floatApprox": 1.426628475177E12}} < / Code> 

and sometimes like it

  {"_id": "nogroup", "value": 9.426533531976E12}  

How can I always remove my long results with the same code?

I currently have

 for  (DBObject a: out.results ()) {return ((BasicBobject) a.get ("value")). Mill Long ("FloatProoprox"); }  

but it only works for the floatApprox version

Just add a check after:

  res = value [i] .endtime;  

For example.

  res = value [i] .endtime; If (type res == "object") {res = res.floatApprox; }  

No comments:

Post a Comment