[SERVER-11467] Odd ouput in MapReduce result. Created: 30/Oct/13  Updated: 11/Jul/16  Resolved: 04/Nov/13

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Critical - P2
Reporter: William Guan Assignee: Amalia Hawkins
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Steps To Reproduce:

exports.basic = function(){
 
    var map = function(){
        var key = {
            app:this.properties.YA0token,
            uuid:this.properties.distinct_id    // for registered user, using user:account
        }
        var value = {
            register:0,
            login:0,
            payment:0,
            transaction:0
        };
 
 
        if (this.event=='register') {
            value.register = 1;
        } else if (this.event=='login') {
            value.login = 1;
        } else if (this.event=='YA0charge') {
            value.payment = this.properties.amount;
            value.transaction = 1;
        }
 
        print(value.register,value.login,value.payment,value.transaction);
 
        emit(key,value);
    }
 
    var reduce = function(key,values){
        var result = {
            register:0,
            login:0,
            payment:0,
            transaction:0
        };
 
        values.forEach(function(value){
            result.register += value.register;
            result.login += value.login;
            result.payment += value.payment;
            result.transcation += value.transcation;
            print('value:',value.register,value.login,value.payment,value.transaction);
        });
        return result;
    }
 
 
    var options = {
//        out:{reduce:"mr_users"},    // reduce : add the value of same key
        out:{merge:"mr_users"},
        query:{
            "event":{$in:["register","login","YA0charge"]},
            "properties.time": {"$gte": new Date("9 1 2013"), "$lt": new Date("9 3 2013")}
        }
    }
 
    eventCollection.mapReduce(map,reduce,options,function (err, collection2) {
        logger.info('MapReduce for basic is done.');
        collection2.find().toArray(function(err,item){
            logger.silly(item);
        });
    });
 
}

Participants:

 Description   

The MapReduce result has some record like this: 'NaN' shouldn't be there.

{ "_id" : { "app" : "2a3a10f13deefdd13568639068f00d46", "uuid" : "0087bbdd-8b76-4f68-a7b1-976a0dca82b3" }, "value" : { "register" : 0, "login" : 2, "payment" : 0, "transaction" : 0, "transcation" : NaN } }
{ "_id" : { "app" : "2a3a10f13deefdd13568639068f00d46", "uuid" : "00d58b56-242d-4bcb-bf53-00ba22477dec" }, "value" : { "register" : 0, "login" : 1, "payment" : 0, "transaction" : 0 } }



 Comments   
Comment by William Guan [ 04/Nov/13 ]

You are right. It is spelling issues. Thanks. But I can't close this issue.

Comment by Amalia Hawkins [ 04/Nov/13 ]

Hi, William!

On line #42 of your steps to reproduce, you've spelled "transaction" as "transcation". Does fixing the typo get rid of the issue?

If not, I have a few questions that will enable me to help debug this problem:

  • Could you please provide one or two example documents from the collection you're running the mapreduce on?
  • Further, are you using any specific frameworks or drivers, or just running this from the mongo shell?
  • Which version of mongod are you using?
Generated at Thu Feb 08 03:25:52 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.