1
I have a repository that makes a query in the collection logsMonitrip
. The method below is called by the service when the user tries to make a query through the company’s cnpj, after that I get the xId
of the collection and try to make an aggregation between the collection erros
and logsMonitrip
, where both of them Xids
are equal, to then return the data I need.
I hope it’s just a syntax error.
let criteria = {};
if(idLog){
criteria["idLog"] = idLog;
}
if(cnpjEmpresaTransporte){
criteria["cnpjEmpresaTransporte"] = cnpjEmpresaTransporte;
}
criteria["idCliente"] = clienteId;
criteria["$and"] = [{"dataHoraEvento": {$gte: dataIni}}, {"dataHoraEvento": {$lte: dataFim}}];
criteria["$lookup"] = [{from: "erros",
localField: "xId",
foreignField: "xId",
as: "Logs" }]
console.info(criteria);
this._logger.info(`LogRepository - obterLogsCnpj - idCliente: ${clienteId} - idLog: ${idLog} - cnpjEmpresaTransporte: ${cnpjEmpresaTransporte} - dataIni: ${dataIni} - dataFim: ${dataFim}`);
return this._prepareResult(criteria);
}
_prepareResult(criteria) {
return this._log.aggregate(criteria, {"_class": 0, "_id": 0}).lean().exec();
}