This is from official MongoDB documentation.
toArray
cursor.toArray(function(err, docs){})
converts the cursor object into an array of all the matching records. Probably the most convenient way to retrieve results but be careful with large datasets as every record is loaded into memory.
collection.find().toArray(function(err, docs){
console.log("retrieved records:");
console.log(docs);
});
What does err and doc mean in cursor.toArray(function(err, docs){})?