De tu código Java leí
como
project only type[1..120] fields and number of such fields in the document
Con esta suposición, puede map-reduce de la siguiente manera:
db.testcol.mapReduce(
function(){
value = {count:0};
for (i = 1; i <= 120; i++) {
key = "type" + i
if (this.hasOwnProperty(key)) {
value[key] = this[key];
value.count++
}
}
if (value.count > 0) {
emit(this._id, value);
}
},
function(){
//nothing to reduce
},
{
out:{inline:true}
});
out:{inline:true}
funciona para conjuntos de datos pequeños, cuando el resultado se ajusta al límite de 16Mb . Para respuestas más grandes, debe output
a una colección, que puede consultar e iterar como de costumbre.