0
I’m having a problem doing research on moongose, I have a function that does research for all ids
which I send when I pass the id
amid "5a01e1dbaf371d00152eae89"
works very well but if I pass by the function so:
function getTripsLocation(line_id, index) {
console.log(line_id);
trip
.aggregate([
{
$match: {
$and: [
{"_line._id": '"' + line_id.toString() + '"'},
{
"createdAt": {
$gte: new Date(moment().subtract(1, 'days').format('YYYY-MM-DD 00:00:00')),
$lte: new Date(moment().subtract(1, 'days').format('YYYY-MM-DD 23:59:00'))
}
}
],
}
},
{
$lookup:
{
from: "locations",
localField: "_id",
foreignField: "trip_id",
as: "local",
},
}
])
.then((data) => {
if (data) {
console.log(index, allLines[index]._id,
moment().subtract(1, 'days').format('YYYY-MM-DD 00:00:00'));
index++;
if (index > allLines.length - 1) {
finishProcess('Finish Task . . .');
} else {
console.log(data);
setTimeout(() => {
if (data.length > 0) {
timeDifferenceCalculation(line_id, data,index);
} else {
getTripsLocation(allLines[index]._id,index);
}
}, 1)
}
}
})
.catch((err) => console.log('catch_error_on_trips', err));
}
for line_id
does not work, and is the same ID. I tried to colocat .toString()
to check if this was the most successful.
This my function getTripsLocation
is recursive !
What can be and how to fix ?
My line object on Mongo looks like this:
_line._id
is an Objectid? if yes, try to pass the query this way https://jsfiddle.net/cgxmtmy0/– BrTkCa
I updated my question, but I tried to use it but it didn’t work well
– Renan Rodrigues
would not be
line_id._id
Renan?– BrTkCa
I could not do here, I had to change my colection and put as objetId ai worked.
– Renan Rodrigues