Cursor

noun

say it: “KUR-ser” /ˈkɝsər/

In MongoDB, the object a query returns that hands over the matching documents a few at a time as you read them.

What is a cursor in MongoDB?

A cursor is what find gives back: not the documents themselves, but a pointer into the results that hands them over a batch at a time. mongosh prints the first 20 and you type it for more; in Node, toArray() reads them all into an array.

const thai = db.recipes.find({ cuisine: "Thai" });   // a cursor, not an array
thai.next().name;   // 'Green Curry'
thai.next().name;   // 'Pad Thai'

In a sentence

  • “The cursor from find gave the first 20 recipes, and typing it showed the next 20.”
  • “In Node, calling toArray() on the cursor turns the matches into an ordinary array.”

Level: Apprentice · More MongoDB terms at this level

Updated

In other subjects