Iterating over a mongodb cursor serially (waiting for callbacks before moving to next document)
A more modern approach that uses async/await: const cursor = db.collection(“foo”).find({}); while(await cursor.hasNext()) { const doc = await cursor.next(); // process doc here } Notes: This may be even more simple to do when async iterators arrive. You’ll probably want to add try/catch for error checking. The containing function should be async or the code … Read more