Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongo - get occurrence of lastnames

Tags:

mongodb

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?

like image 808
Raisen Avatar asked Dec 16 '22 15:12

Raisen


1 Answers

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

like image 134
AdaTheDev Avatar answered Dec 19 '22 06:12

AdaTheDev