Я использую рамки mongoose для связи с mongodb. Теперь я в ситуации, чтобы присоединиться к двум коллекциям, используя mapReduce. Я последовал за этой учительницей «http://blog.knoldus.com/2014/03/12/easiest-way-to-implement-joins-in-mongodb-2-4/», чтобы сделать это. Я успешно сделал с присоединением, используя mapReduce в mongoDB Shell, используя robomongo. То же самое я пытаюсь работать с рамкой mongoose, но это дает мне ошибку, которую должен игнорировать параметр Out.Mongoose mapReduce Ошибка: параметр OUT должен быть определен
Образец кода, что я сделал.
Это коллекция схемы для профиля пользователя:
var User = new mongoose.Schema({
name : {
first : {type : String},
last : {type : String}
},
title : {type : String},
userName : {type : String, unique : true},
profileImgUrl : {type : String},
mojo : Number
});
это коллекция схемы для отзывов:
var Testimonials = new mongoose.Schema({
from : String,
to : String,
text : String
});
Это код, используя мангуст, nodejs: -
var mapTalent = function() {
var output= {userName : this.userName,firstname:this.name.first, lastname:this.name.last , profileImgUrl : this.profileImgUrl, mojo : this.mojo, text : null}
emit(this.userName, output);
};
var mapTestimonial = function() {
var output = {fromTalentName : this.fromTalentName, firstname:null, lastname:null, profileImgUrl : null, mojo : null, text : this.text}
emit(this.text, output);
};
var reduceF = function(key, values) {
var outs = {firstname:null, lastname:null , profileImgUrl:null, text : null, mojo:null};
values.forEach(function(v){
if(outs.firstname ==null){
outs.firstname = v.firstname
}
if(outs.lastname ==null){
outs.lastname = v.lastname
}
if(outs.profileImgUrl ==null){
outs.profileImgUrl = v.profileImgUrl
}
if(outs.mojo ==null){
outs.mojo = v.mojo
}
if(outs.text == null){
outs.text = v.text
}
});
return outs;
};
result = Testimonials.mapReduce(mapTestimonial, reduceF, {out : {reduce : "Talent_Testimonials"}});
result = Talent.mapReduce(mapTalent, reduceF, {out : {reduce : "Talent_Testimonials"}});
Здесь ошибка выбрана так: «должен быть определен параметр опции out».
Что я делаю неправильно здесь, я не получаю. Это же работает в оболочке mongoDB.