hasNext()/next()

Reference type:Cheat sheetFormat:Syntax + example + use case

Reference group: Cursor methods

What it does

Checks for and retrieves the next result.

Syntax

cursor.hasNext(); cursor.next()

Use case

Process records incrementally.

hasNext()/next(): practical example
const c = db.orders.find({ status: "open" }); if (c.hasNext()) printjson(c.next())
💡 Explanation Checks for and retrieves the next result. When to use it Process records incrementally.
Key Takeaways
  • Checks for and retrieves the next result.
  • Typical use: Process records incrementally.