[JAVA-1317] The MapReduce output field "Ok" value is not correct Created: 22/Jul/14  Updated: 23/Jul/14  Resolved: 22/Jul/14

Status: Closed
Project: Java Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Dong [X] Assignee: Ross Lawley
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Mongodb 2.6.3, java driver 2.12.3


Attachments: Java Source File MapReduceTest.java    

 Description   

The map reduce out put is

 
{ "serverUsed" : "localhost:27017" , 
  "results" : [ { "_id" : "Bui01" , "value" : 40.0} , { "_id" : "Bui02" , "value" : 52.0}] , 
  "timeMillis" : 2 , "timing" : { "mapTime" : 0 , "emitLoop" : 1 , "reduceTime" : 1 , "mode" : "mixed" , "total" : 2} , 
  "counts" : { "input" : 5 , "emit" : 5 , "reduce" : 2 , "output" : 2} , "ok" : 1.0},  

but the field "ok" is 1.0, it should be 1, it's not correct.



 Comments   
Comment by Ross Lawley [ 23/Jul/14 ]

Hi Dong that all looks fine. The "ok" value in a command result is set as a Double by the server so 1.0 is the correct representation.

Other than being represented differently in the shell (for the reasons mentioned above) is there any other reason why you think it should be an integer?

Comment by Dong [X] [ 23/Jul/14 ]

Hi Ross,

I have not use command result for an inline map reduce, I used Mapreduceoutput for merge, and my java code in the attachment, please check it.

Comment by Ross Lawley [ 22/Jul/14 ]

Hi Rambo,

I think you are referring to the command result for an inline map reduce? And the differences between the shell representation and Java?

The command result is a wrapper of a DBObject and as such is handled the same as any DBObject coming from the server. CommandResults return a double value for the "ok" field which is why its expressed as 1.0

So why is this different from the shell? In truth its not different! However, in javascript the representation of numbers is different and the mongo shell treats all numbers as floating-point values [1].

You can test that in JS 1 and 1.0 are the same in the shell by doing:

> var a = 1.0
> typeof a
number
> a
1 // The Javascript representation of 1.0 is 1 !

So they appear to be different in the string representations of the command result document - however the types are the same and that is why in Java it is a Double. I hope that clarifies why they appear to be different.

It should also be noted access to the commandResult via the getCommandResult() or getRaw() methods are deprecated and due to be removed in the future.

[1] http://docs.mongodb.org/manual/core/shell-types/#numberint

Generated at Thu Feb 08 08:54:18 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.