Mongo - get lastnames appear

I want to know what the appearance of the last names in the collection is. I am 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: options neededOrOutString

Any ideas?

+4
source share
1 answer

If you use> v1.7.4, you need to specify output options:

eg.

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

This will save the results in the named collection. See the output parameters section in the docs: http://www.mongodb.org/display/DOCS/MapReduce

+12
source

Source: https://habr.com/ru/post/1346621/


All Articles