Cursors and Batches
find returns a cursor that fetches documents in batches. Use toArray for small results, iterate for large ones and avoid loading millions into memory.
Example
const cursor = db.students.find({ age: { $gt: 20 } })
while (cursor.hasNext()) {
printjson(cursor.next())
}
db.students.find().toArray()Exercise
Convert to an array.
cursor.()
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.