# process-collection

> Call a function each document in a MongoDB collection

Latest version **1.0.0** (published 2020-04-28) · 0 weekly downloads

## Install

```sh
npm install process-collection
pnpm add process-collection
yarn add process-collection
bun add process-collection
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2020-04-28 |
| First published | 2020-04-28 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Ryan Yeske |
| Maintainers | ryborg |

## Links

- npm: https://www.npmjs.com/package/process-collection
- npm.io page: https://npm.io/package/process-collection

## Recent versions

- 1.0.0 (latest) — 2020-04-28

## README

# Process Collection

Run a function on documents in collections asyncronously and with progress indicator.

# Setup

Install dependencies:

```
npm install
```

To run the test example:

```
make
```

This assumes you have mongo running on localhost port 3001, with a database called `meteor` that contains a `clients` collection.

The makefile directs standard output to `output.log` while displaying process to stderr.

# processCollection

This function has a single argument with properties:

* `collection`: mongo collection
* `query`: a mongo query on the collection
* `projection`: projection to limit the fields (might be broken, but would be helpful for large documents over the network)
* `sort`: sort
* `limit`: limit
* `showProgress`: boolean, default true: output progress with eta to stderr
* `handler`: handler function that takes a single document

example:

```js
const connect = require('./lib/connection')
const processCollection = require('./lib/process-collection')

connect('mongodb://localhost:3001/meteor').then(async client => {
  const Clients = client.db().collection('clients')

  await processCollection({
    collection: Clients,
    query: { created_at: { $gte: new Date("2016-01-01" ) } },
    handler: function(doc) {
      console.log(doc._id);
    }
  })

  client.close()
})
```

The above will output the `_id` of each document in the `clients` collection from the `meteor` database on `localhost:3001`.

---
_Source: https://npm.io/package/process-collection · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
