selecting all the fields in a row using mapReduce selecting all the fields in a row using mapReduce mongoose mongoose

selecting all the fields in a row using mapReduce


I must admit I'm not sure I understand completely what you're asking.But maybe one of the following thoughts helps you:

either) when you iterate over your mapReduce results, you could fetch complete documents from mongodb for each result. That would give you access to all fields in each document for the cost of some network traffic.

or) The value that you send into emit(key, value) can be an object. So you could construct a value object that contains all your desired fields. Just be sure to use the exactly same object structure for your reduce method's return value.

I try to illustrate with an (untested) example.

map = function() {   emit(this.place,         {           'field1': this.field1,            'field2': this.field2,            'count' : 1         });}reduce = function(key, values) {   var result = {        'field1': values[0].field1,        'field2': values[0].field2,        'count' : 0 };   for (v in values) {       result.count += values[v].count;   }   return obj;}