Raisen
Raisen

Reputation: 4495

Mongo - get occurrence of lastnames

I want to find out what's the occurrence of lastnames in a collection. I'm using the following:

m = function() { this.lastname.forEach( function(z) { emit( z , { count : 1 } ); }); };
r = function(p, c) { var total = 0; for (var i =0; i < c.length; i++) total += c[i].count; return { count : total }; };

res = db.properties.mapReduce(m,r);

I get the following error:

uncaught exception: assert failed : need to an optionsOrOutString

Any ideas?

Upvotes: 4

Views: 2566

Answers (1)

AdaTheDev
AdaTheDev

Reputation: 147264

If you're using > v1.7.4 then you need to specify the out options:

e.g.

res = db.properties.mapReduce(m,r, {out: "CollectionToOutputResultsTo"});

This will store the results into the named collection. See the output options section of the docs here: http://www.mongodb.org/display/DOCS/MapReduce

Upvotes: 12

Related Questions