Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-16045

null value in mapReduce results

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • None
    • MapReduce
    • None
    • OS X

    Description

      db version v2.6.4

      I have ~100 entries (dump in attach) in my collection and try to do mapReduce on it with the following command

      db.features.mapReduce(
        function () {
          emit(this._quadKey.substr(0, 1), this );
        },
        function (key, values) {
          var result = { q: [], ids: [] };
          values.forEach(       
            function (it) {
              result.q.push(it._quadKey);
              result.ids.push(it._id);
            }
          );
          return result; 
        },
        {
          query: { _quadKey: { $regex: '^(0|1|2|3)' } },
          out: { inline: 1 } 
        }
      )

      "_quadKey" field which is used for grouping in Map function is a string of base-4 numbers that looks like "33100321300223132221023"

      As a result of this command i got 5 reduce calls instead of 4 (see stat)
      and a "null" value in last group with "3" key and i got only 2 (except null) entries there (should be 20+).

      {
              "results" : [
                      {
                              "_id" : "0",
                              "value" : {
                                      "q" : [
                                              "00211222022320022310003",
      ...
                                              "03332223130001223231310"
                                      ],
                                      "ids" : [
                                              ObjectId("545e7065eb6be425a700003a"),
      ...
                                              ObjectId("545e7052eb6be425a700002c")
                                      ]
                              }
                      },
                      {
                              "_id" : "1",
                              "value" : {
                                      "q" : [
                                              "10033101320022232203331",
      ...
                                              "13331332032210022212221"
                                      ],
                                      "ids" : [
                                              ObjectId("545e709beb6be425a700005f"),
      ...
                                              ObjectId("545e7043eb6be425a700001e")
                                      ]
                              }
                      },
                              "_id" : "2",
                              "value" : {
                                      "q" : [
                                              "20003331310022201013110",
      ...
                                              "23302313120113202111313"
                                      ],
                                      "ids" : [
                                              ObjectId("545e7050eb6be425a700002a"),
      ...
                                              ObjectId("545e7063eb6be425a7000038")
                                      ]
                              }
                      },
                      {
                              "_id" : "3",
                              "value" : {
                                      "q" : [
                                              null,
                                              "33100321300223132221023",
                                              "33101232232201203113211"
                                      ],
                                      "ids" : [
                                              null,  // Here it is!!!     
                                              ObjectId("545e7059eb6be425a7000031"),
                                              ObjectId("545e7081eb6be425a7000052")
                                      ]
                              }
                      }
              ],
              "timeMillis" : 12,
              "counts" : {
                      "input" : 102,
                      "emit" : 102,
                      "reduce" : 5,
                      "output" : 4
              },
              "ok" : 1

      Also I have noticed that group where I've got "null" depends on index
      if I crete index for "_quadKey" field I'he got null in last key "3" group

      db.features.ensureIndex({ _quadKey: 1 })

      If i drop this index I've got this issue in first "0" group

      db.features.dropIndex({ _quadKey: 1 })

      {
              "results" : [
                      {
                              "_id" : "0",
                              "value" : {
                                      "q" : [
                                              null,
                                              "00222330102200231213001",
                                              "00211222022320022310003"
                                      ],
                                      "ids" : [
                                              null,
                                              ObjectId("545e701eeb6be425a7000004"),
                                              ObjectId("545e7065eb6be425a700003a")
                                      ]
                              }
                      },
      ...
              ],
              "timeMillis" : 6,
              "counts" : {
                      "input" : 102,
                      "emit" : 102,
                      "reduce" : 5,
                      "output" : 4
              },
              "ok" : 1
      }

      Attachments

        Activity

          People

            ramon.fernandez@mongodb.com Ramon Fernandez Marina
            dimik Dmitry Poklonskiy
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: