I am a beginner in mongodb and javascript.
I have here a code for simple find method in Mongodb Nodejs. This code does not work.
The solution is to change the last line to this: cursor.limit(10).toArray((err, docs) => console.log(docs));
.
What I do not understand is why do I need to include the err
argument here? Here is the documentation for toArray method. It does not say here that err
parameter is needed. How would I know that err
argument is needed here or in other methods?
Thank you very much! I think this is a very basic concept and I will appreciate any input.
const client = new MongoClient(uri);
client.connect()
.then(() => {
const db = client.db('sample_mflix');
const coll = db.collection('movies');
const cursor = coll.find();
cursor.limit(10).toArray((docs) => console.log(docs));
})