0

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){})?

Stennie
  • 63,885
  • 14
  • 149
  • 175
geoyws
  • 3,326
  • 3
  • 35
  • 47
  • 1
    err - error if happened during reading from cursor. If no error then null. Docs - array of documents read from cursor. – Andrei Beziazychnyi May 18 '14 at 19:22
  • Better documentation for `toArray` can be found here: http://mongodb.github.io/node-mongodb-native/api-generated/cursor.html#toarray – JohnnyHK May 18 '14 at 19:24

1 Answers1

1

docs is an array with all the documents returned by the cursor.

When there was an error, err is an object which describes that error.

Philipp
  • 67,764
  • 9
  • 118
  • 153