Есть модели и несколько записей в них:
Personage({
id: 1,
note_id: 3,
name: "neme",
number: 4
},
{
id: 2,
note_id: 1,
name: "neme",
number: 5
},
{
id: 3,
note_id: 2,
name: "neme",
number: 3
});
Note({
id: 1,
body: "first-text1",
text: "text3"
},
{
id: 2,
body: "first-text2",
text: "text2"
},
{
id: 3,
body: "first-text3",
text: "text3"
});
Как имея значение поля “text” модели Note (например “text3”) получить все обекты модели Personage свойство “note_id” которых
совпадает с id записи модели Note в котором ести свойство “text” с значением “text3”;
Пробовал так:
Note.find({text: "text3"}, function (err, note) {
console.log("start");
for(var i = 0; i < note.length; i++){
console.log("1");
Personage.find(function (err, personage) {
console.log("2");
for(var j = 0; j < personage.length; j++){
console.log("3");
if(note[i].id === personage[j].note_id){
console.log("end");
console.log(personage[j]);
}
}
})
}
});
Выводит: start,1,1,1,2,3,3,3
end так и не выводится.
Как бить?