mongo-iterable-cursor
Turn your mongodb cursor into an async iterable.
Async iteration is a stage-3 proposal. Use with caution!
Without babel
You'll need Node.js 4 or above.
const MongoClient = ;const iterable = ; MongoClient ;
You can use for-await to handle your items serially.
const forAwait = ;const MongoClient = ;const iterable = ; MongoClient ;
With babel
Your setup needs to support async generator functions. If you are using Babel you'll need at least the following config.
"presets": "es2017" // or use Node.js v8 which includes async/await "plugins": "transform-async-generator-functions"
const iterable = ;const MongoClient = ; async { const db = await MongoClient; const users = db; for await const user of // };
Register
Requiring mongo-iterable-cursor/register
adds [Symbol.asyncIterator]
to the mongodb cursor Cursor.prototype
.
; const MongoClient = ; async { const db = await MongoClient; const users = db; for await const user of users // };