💻 Take your coding skills to the next level with "500+ Ultimate ChatGPT Prompts For Developers" – the game-changer every developer needs, click here to order now.

Cursor-based iteration with Mongoose

Published November 17, 2021Last updated May 28, 20231 min read

Using cursor-based iteration can be useful when there is a need to iterate (in memory) over all of the documents from a collection and every document is a big object. Every document can be projected to return only specific fields.

const cursor = Model.find().select('/* several fields */').cursor();
for (let document = await cursor.next(); document != null; document = await cursor.next()) {
// ...


© 2023