[SERVER-20495] MapReduceResult.find() and drop() error when outputting to a different DB Created: 18/Sep/15  Updated: 01/Oct/19  Resolved: 01/Oct/19

Status: Closed
Project: Core Server
Component/s: MapReduce, Shell
Affects Version/s: 3.1.8
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Robert Guo (Inactive) Assignee: Robert Guo (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-42675 M/R Agg: Remove MapReduceResult shell... Closed
Operating System: ALL
Steps To Reproduce:

t = db.mr;
t.drop();
 
t.save( { x : 1 , tags : [ "a" , "b" ] } );
t.save( { x : 2 , tags : [ "b" , "c" ] } );
t.save( { x : 3 , tags : [ "c" , "a" ] } );
t.save( { x : 4 , tags : [ "b" , "c" ] } );
 
m = function(){
    this.tags.forEach(
        function(z){
            emit( z , { count : 1 } );
        }
    );
};
 
r = function( key , values ){
    var total = 0;
    for ( var i=0; i<values.length; i++ ){
        total += values[i].count;
    }
    return { count : total };
};
 
res = t.mapReduce(m , r , {out : { replace: "outColl", db: "outDb" } });
outDB.outColl.find().count()
res.find().count() // error, no results

Participants:

 Description   

DBCollection's mapreduce function returns a MapReduceResult object, which takes in the result of db.runCommand(mapreduce).

If the output is to a different db (i.e. when the "out" parameter is specified with an action instead of a collection name), the result is an object instead of a collection name string.

This is passed into MapReduceResult and stored as the collection name, which in this case gets parsed as the string "[object BSON]". This variable is used by MapReduceResult.find() and MapReduceResult.drop().

The two functions are not documented so maybe they could be cleaned up a bit.



 Comments   
Comment by Arun Banala [ 25/Sep/19 ]

robert.guo Now that SERVER-42675 is implemented. I think this ticket can be closed.

Generated at Thu Feb 08 03:54:23 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.