Nocturnally Psychologizing Millipede
    Have ideas to improve npm?Join in the discussion! »

    batch-mobile

    1.2.3 • Public • Published

    batch-mobile 🦇

    Batch Cave npm version vulnerabilities

    Asynchronous batched iterable for (mongo) cursors

    A library when one is not enough and all is to much.

    Installation

    npm i batch-mobile

    API

    getBatchedIterableFromCursor(cursor, batchSize)

    • cursor: Any iterable cursor which exposes an aynchronous next method
    • batchSize: The size of the yielded batch. Defaults to 200 if unset.

    Usage

    Simple example

    const { getBatchedIterableFromCursor } = require('batch-mobile')
    for await (const batchOfItems of getBatchedIterableFromCursor(cursor)) {
      await pushBatchToService(batchOfItems)
    }

    Mongo example

    const { MongoClient } = require('mongodb')
    const client = await (new MongoClient(process.env.MONGO_URI)).connect()
    const { getBatchedIterableFromCursor } = require('batch-mobile')
     
    try {
      const collection = client.db('application').collection('collection')
      const cursor = collection
        .find({ foo: 'bar' })
     
      for await (const batch of getBatchedIterableFromCursor(cursor, 1000)) {
        await processItemsFrom(batch)
      }
    } finally {
      await client.close(true)
    }

    Install

    npm i batch-mobile

    DownloadsWeekly Downloads

    32

    Version

    1.2.3

    License

    MIT

    Unpacked Size

    7.83 kB

    Total Files

    9

    Last publish

    Collaborators

    • avatar