Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-1248

Comment on: "manual/applications/map-reduce.txt"

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None

    Description

      I find a strange problem when I use map-reduce,here is the description:
      first I insert data into database like this:
      //insert.js
      for(var i=0;i<5;i++){
      db.RegistRecord.save(

      {"ip":"11.11.11.11","account":"ongyong"}

      );
      }

      for(var i=0;i<2;i++){
      db.RegistRecord.save(

      {"ip":"11.11.11.22","account":"ongyong22"}

      );
      }
      for(var i=0;i<1;i++){
      db.RegistRecord.save(

      {"ip":"11.11.11.33","account":"ongyong33"}

      );
      }

      then run map-reduce through a javascript like this:

      //regmp.js
      printjson("job start");
      var map = function() {
      emit(this.ip,

      {value: 1}

      );
      }

      var reduce = function(key, values) {
      var count = 0;
      values.forEach(function(v)

      { count += v['value']; }

      );
      return

      {count: count }

      ;

      }

      var res = db.runCommand(

      {mapreduce:"RegistRecord",map:map, reduce:reduce, out:"log_results"}

      );
      printjson("job end")

      Ok,you'll find the result is no problem and like this:
      /* 0 */
      {
      "_id" : "11.11.11.11",
      "value" :

      { "count" : 5.0 }

      }

      /* 1 */
      {
      "_id" : "11.11.11.22",
      "value" :

      { "count" : 2.0 }

      }

      /* 2 */
      {
      "_id" : "11.11.11.33",
      "value" :

      { "value" : 1.0 }

      }

      but,when the records increase to 2000,strange problem comes:
      insert data first like this :
      //insert.js
      for(var i=0;i<2000;i++){
      db.RegistRecord.save(

      {"ip":"11.11.11.11","account":"ongyong"}

      );
      }

      for(var i=0;i<2;i++){
      db.RegistRecord.save(

      {"ip":"11.11.11.22","account":"ongyong22"}

      );
      }
      for(var i=0;i<1;i++){
      db.RegistRecord.save(

      {"ip":"11.11.11.33","account":"ongyong33"}

      );
      }

      run the same script and the result is like this :
      /* 0 */
      {
      "_id" : "11.11.11.11",
      "value" :

      { "count" : NaN }

      }

      /* 1 */
      {
      "_id" : "11.11.11.22",
      "value" :

      { "count" : 2.0 }

      }

      /* 2 */
      {
      "_id" : "11.11.11.33",
      "value" :

      { "value" : 1.0 }

      }

      see the fird record ? "NaN"??
      And I also find that the data reduce function received is strange:

      /* 0 */
      {
      "_id" : "11.11.11.22",
      "value" : {
      "count" : [

      { "value" : 1.0 }

      ,

      { "value" : 1.0 }

      ]
      }
      }

      /* 1 */
      {
      "_id" : "11.11.11.33",
      "value" :

      { "value" : 1.0 }

      }

      /* 2 */
      {
      "_id" : "11.11.11.11",
      "value" : {
      "count" : [{
      "count" : [

      { "value" : 1.0 }

      ,

      { "value" : 1.0 }

      ,

      { "value" : 1.0 }

      ,
      。。。。

      Sorry for my poor English...
      hope for your response!

      Attachments

        Activity

          People

            kay.kim@mongodb.com Kay Kim (Inactive)
            auto auto
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              10 years, 46 weeks, 1 day ago