2.0.1 • Published 4 years ago

mongo-each v2.0.1

Weekly downloads
33
License
MIT
Repository
github
Last release
4 years ago

mongo-each

Build Status Coverage Status NPM Version

Queued asynchronous iterating over mongodb cursor

API

each(cursor, iteratee, [options])

  • cursor - a mongodb cursor
  • iteratee - function(doc) - iteratee function, should return promise
  • options - optional concurrency - how many iteratee functions should be run in parallel (default: 100) batch - batch mode (default: false) * batchSize - batch size (default: 10)

Returns promise which is resolves when all iteratee functions have finished, or rejects if an error occurs

Example

const {MongoClient} = require('mongodb');
const each = require('mongo-each');

async function main() {
	const db = await MongoClient.connect('mongodb://127.0.0.1:27017/mongo-each');
	const collection = db.collection('data');
	const cursor = collection.find();

	await each(collection.find(), async (doc) => {
		console.log(doc)

		await delay(100);
	}, {concurrency: 50});
}

function delay(ms) {
	return new Promise((resolve) => {
		setTimeout(resolve, ms);
	});
}

main();

License

MIT

2.0.1

4 years ago

2.0.0

5 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

9 years ago