[DOCS-1248] Comment on: "manual/applications/map-reduce.txt" Created: 16/Mar/13 Updated: 03/Nov/17 Resolved: 02/Apr/13 |
|
| Status: | Closed |
| Project: | Documentation |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | auto | Assignee: | Kay Kim (Inactive) |
| Resolution: | Done | Votes: | 0 |
| Labels: | collector-298ba4e7 | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
redhat linux 64bit Location: http://docs.mongodb.org/manual/applications/map-reduce/ |
||
| Participants: | |
| Days since reply: | 10 years, 46 weeks, 1 day ago |
| Description |
|
I find a strange problem when I use map-reduce,here is the description: ); for(var i=0;i<2;i++){ ); ); then run map-reduce through a javascript like this: //regmp.js ); var reduce = function(key, values) { ); ; } var res = db.runCommand( {mapreduce:"RegistRecord",map:map, reduce:reduce, out:"log_results"}); Ok,you'll find the result is no problem and like this: } /* 1 */ } /* 2 */ } but,when the records increase to 2000,strange problem comes: ); for(var i=0;i<2;i++){ ); ); run the same script and the result is like this : } /* 1 */ } /* 2 */ } see the fird record ? "NaN"?? /* 0 */ , { "value" : 1.0 }] /* 1 */ } /* 2 */ , { "value" : 1.0 }, { "value" : 1.0 }, Sorry for my poor English... |
| Comments |
| Comment by Kay Kim (Inactive) [ 02/Apr/13 ] |
|
Thank you so much for your comment. With map-reduce, the reduce function must have the following property: reduce( key, [ reduce(key, valuesArray) ] ) == reduce( key, valuesArray ) Your reduce function does not share the property: var reduce = function(key, values) { ); ; that is reduce("11.11.11.11", [ reduce("11.11.11.11", [ { value: 1 }] ) ] ) does not equal reduce( "11.11.11.11", [ {value: 1}] ) If you try: var map = function() { var reduce = function(key, values) { this should work for you. The http://docs.mongodb.org/manual/reference/method/db.collection.mapReduce page lists (around the middle of the page) the requirements for the map and reduce functions Hope this answers your question. |