Я работаю с 2 схемами из mon go db
Я хочу найти все случаи, связанные с пользователем (каждый случай состоит из идентификаторов из других схем)
После того, как я обнаружил все случаи, которые я хочу пропустить через них oop, и нашел бы customerType (еще один schmea, связанный с каждым случаем), затем создайте новый массив объектов, который будет выглядеть примерно так [{case: case [i ], customerType: foundEle}, {case: case [i], customerType: foundEle}]
Это мой код, я довольно новичок во всем этом
client.findOne({_id: req.user.userType}, function(err, foundClient){
if(err){
console.log(err)
}else{
cases.find({client: foundClient._id}, function(err, foundCases){
if(err){
console.log(err);
}else{
var foundEle;
var x = [];
function match(cases, ele){
for(var i = 0; i < cases.length; i++){
foundEle = ele.findOne({_id: cases[i].buyerType}, function(err, foundBuyerType){
if(err){
console.log(err);
}else{
return foundBuyerType;
}
});
x.push({case: cases[i], type: foundEle});
}
return x
}
match(foundCases, buyerType);
console.log(x)
res.render("./dashboard/client/dashboard",
{
user: user,
metatitle: metatitle,
metadescription: metadescription,
foundClient: foundClient,
foundCases: foundCases,
});
};
});
}
})
Я получение следующего ответа
{ case:
{ buyerType: [Array],
broker: [Array],
client: [Array],
initialFactFind: [],
factFind: [],
futurePlan: [],
options: [],
product: [],
documents: [],
lenderQuestion: [],
tracking: [],
_id: 5e204259b68a1724b0efe9ec,
__v: 2 },
type:
Query {
_mongooseOptions: {},
_transforms: [],
_hooks: [Kareem],
_executionCount: 0,
mongooseCollection: [NativeCollection],
model: Model { buyerType },
schema: [Schema],
op: 'findOne',
options: {},
_conditions: [Object],
_fields: undefined,
_update: undefined,
_path: undefined,
_distinct: undefined,
_collection: [NodeCollection],
_traceFunction: undefined,
'$useProjection': true } },
Элемент case ответа в порядке, но типовая часть ответа должна совпадать с элементом case вместо ref для самой модели.
Любая помощь приветствуется. Я новичок в этом вопросе, так что это, вероятно, глупый вопрос.
Спасибо за любую помощь