Problems with mongoose searches

0

I'm having a problem to do a search on moongose, I have a function that does searches for all the ids I send but when I pass the id between "5a01e1dbaf371d00152eae89" it works very well however if I go through the function like this: / p>

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));
  }

by line_id does not work, and is the same ID. I tried putting .toString() to check if this was more I did not succeed.

This my function getTripsLocation is recursive!

What can be and how to correct?

My mongo line object looks like this:

    
asked by anonymous 29.01.2018 / 12:46

0 answers