function querydb(){
cursor = dbConnection.collection("logs").find(queryObj).limit(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], 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();
}
}
);
};
Here is my querydb function. As you can see i check if the value is not equal to null and if its true i call writeFile. but in the .txt it just prints "object object". Any idea on whats going on??