writeFile只写一个语句/日志

时间:2016-03-04 04:02:47

标签: javascript writefile

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

我在querydb函数中调用writeFile。我不明白为什么它没有编写我调用的所有日志而只是将一个日志写入我的txt文件。

0 个答案:

没有答案