This question already has an answer here:
- Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference 3 answers
I am trying to convert my find cursor object into an array using the toArray() function. I have been having trouble understanding the callback required in this function and have tried implementing it in the following way but it returns undefined. Any help on how to use the toArray() method is much appreciated
var collection = db.collection('notes');
var find = collection.find(cr);
var findArray = [];
findArray = find.toArray(function(err, items){
findArray = items;});
console.log("Found: ");
console.log(findArray);
Aucun commentaire:
Enregistrer un commentaire