0
function querydb() {
  cursor = dbConnection.collection("logs").find(queryObj).limit(parseInt(valueList[1]));

  /*Either decide here to foreach for file or for console OR...*/
  cursor.forEach(function(item) {
    /*Decide here whether to write to file or console*/
    if (valueList[0] != null) {
      fs.writeFile(valueList[0], JSON.stringify(item), 'utf-8', console.log("finished!!"));
    }
    if (valueList[0] == null) {
      console.log(item);
      console.log("Done");
    }

    /*CHECK TO SEE IF THE CURSOR IS EXHAUSTED*/
    if (cursor == null) {
      //now we can close the database
      dbConnection.close();
    }
  });
};

I call writeFile in my querydb function. I don't understand why its not writing all the logs I'm calling instead its just writing one log to my txt file.

Raviteja
  • 3,399
  • 23
  • 42
  • 69

0 Answers0