[SERVER-5168] Map Reduce Incorrectly Emitting null When a Constant Key is Used Created: 02/Mar/12 Updated: 15/Aug/12 Resolved: 07/Mar/12 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | JavaScript, MapReduce, Querying |
| Affects Version/s: | 2.0.3 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Critical - P2 |
| Reporter: | Alexander Nagy | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | mapreduce,, mongos, query | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Windows Server 2K8R2 x64 |
||
| Operating System: | ALL |
| Participants: |
| Description |
|
Running MapReduce with a constant key causes null to always be emitted. This makes any scenario where you need to perform global aggregation on the server impossible. While the repro code below is trivial, our actual production code performs much more sophisticated analysis logic on objects. The following repro code below will assert in the reduce function: db.items.mapReduce(function () { ); emit(key, { a: sum }); }, { out: "foo_out" }); "assertion" : "invoke failed: JS Error: TypeError: value has no properties nofile_b:2", "assertionCode" : 9004, "errmsg" : "db assertion failure", "ok" : 0 Note that just a simple change in the id causes the failure to go away (this is not functionally equivalent, nor is it a workaround, but it illustrates the bug): db.items.mapReduce(function () { emit(this._id, { a: 1 }); }, function (key, values) { var sum = 0; values.forEach(function (value) { sum += value.a; } ); ); ); "result" : "foo", , |
| Comments |
| Comment by Eliot Horowitz (Inactive) [ 07/Mar/12 ] |
|
You can't emit from a reduce function. |