[SERVER-22922] mapReduce return incorrect result Created: 02/Mar/16 Updated: 08/Mar/16 Resolved: 07/Mar/16 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | MapReduce |
| Affects Version/s: | 3.2.1 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Critical - P2 |
| Reporter: | Oded Shafran | Assignee: | Kelsey Schubert |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Operating System: | ALL |
| Participants: |
| Description |
|
I have the following code (in ruby using mongoid)
Problem is, that count == 2. while I have a couple of hundreds of documents |
| Comments |
| Comment by Oded Shafran [ 08/Mar/16 ] | ||
|
Got it. thanks | ||
| Comment by Asya Kamsky [ 07/Mar/16 ] | ||
|
I think you misunderstand.
works fine because it's incrementing "running count" by new value. What your code does is
| ||
| Comment by Oded Shafran [ 07/Mar/16 ] | ||
|
Thanks. So you are saying that it is inevitable always to check if the "field" in the emitter exists, by doing that - understanding if i'm being pushed from a previous call. | ||
| Comment by Ramon Fernandez Marina [ 07/Mar/16 ] | ||
|
odedshafran, please take a look at | ||
| Comment by Oded Shafran [ 07/Mar/16 ] | ||
|
Thank you @Thomas. var reduceFunction2 = function(keySKU, countObjVals) { ; for (var idx = 0; idx < countObjVals.length; idx++) { reducedVal.count += countObjVals[idx].count; reducedVal.qty += countObjVals[idx].qty; } return reducedVal; countObjVals is always NOT an array. how is that settled with what you've written? Thank you | ||
| Comment by Kelsey Schubert [ 07/Mar/16 ] | ||
|
Hi odedshafran, The reduce function described does not meet the necessary requirements. In particular, please note the following behavior:
If you continue to run into issues with your reduce function, I would recommend posting on the mongodb-users group or Stack Overflow with the mongodb tag. A question like this involving more discussion would be best posted on the mongodb-users group. Thank you, | ||
| Comment by Oded Shafran [ 02/Mar/16 ] | ||
|
I have this collection sharded and in replica set. if it makes any difference. on my local machine it is not reproduceable |