toArray()
Reference group: Cursor methods
What it does
Materializes all remaining results into an array in the client.
Syntax
cursor.toArray()
Use case
Use array operations on a bounded result.
Important notes
Avoid unbounded result sets.
toArray(): practical example
const recent = db.orders.find({ status: "open" }).limit(100).toArray()💡 Explanation
Materializes all remaining results into an array in the client.
When to use it
Use array operations on a bounded result.
Caution
Avoid unbounded result sets.
Key Takeaways
- Materializes all remaining results into an array in the client.
- Typical use: Use array operations on a bounded result.