Answer the question
In order to leave comments, you need to log in
What is the correct way to write mapReduce for MongoDB?
Good afternoon. Please help me figure it out. There is a collection of bankGuarantee
I write mapReduce like this:
var map = function(){
var key = {
regNum: this.regNumber,
bank_name: this.bank.shortName,
bank_inn: this.bank.INN,
year: this.guarantee.guaranteeDate.getFullYear(), //Дата выдачи БГ.Год
month: this.guarantee.guaranteeDate.getMonth(), //Дата выдачи БГ.Месяц
category: getCategory(this.guarantee.guaranteeAmount)
};
emit(key, {count:1, bg_amount: this.guarantee.guaranteeAmount /*,Сумма контракта*/});
}
var reduce = function(key, values){
var bg_count = 0;
var bg_amount = 0;
values.forEach(function(value) {
bg_count += value['count'];
bg_amount += value['bg_amount'];
});
return {count: bg_count, amount: bg_amount};
}
db.bankGuarantee.mapReduce(map, reduce, {out: 'bg_stats'});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question