npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

errand-mongodb

v0.1.5

Published

errand component for working with mongodb

Readme

errand-mongodb

errand worker component used for mongodb

Usage


npm install errand-mongodb

Notes:

  1. For dependencies and suggested usage of errand worker components refer to errand
  2. Set environment variable ERRAND_MONGODB_URL with connection string for mongodb server, if not set module will default to mongodb://localhost:27017

Example


{
	"tasks": [

		{
			"task": "errand-mongodb",
			"data": {
				"description": "replace-with-task-description",
				"request": {
					"method": "replace-with-mongodb-method",
					"parameters": {
						...
					}
				}
			}
		}

	]
}

Notes:

  • tasks - errand task list
  • tasks[].task - required errand-mongodb task name
  • tasks[].data.description - optional task description
  • tasks[].data.request.method - required mongodb method
  • tasks[].data.request.parameters - required mongodb method parameters, the parameter payload will vary depending on method

db.collection.aggregate Example


{
	"tasks": [
		{
			"task": "errand-mongodb",
			"data": {
				"description": "replace-with-task-description",
				"request": {
					"method": "db.collection.aggregate",
					"parameters": {
						"database": "errand_test",
						"collection": "orders",
						"pipeline": [
							{ "$match": { "status": "A" } },
							{ "$group": { "_id": "$cust_id", "total": { "$sum": "$amount" } } },
							{ "$sort": { "total": -1 } },
							{ "$out": "errand_aggregate_test_result" }
						],
						"helpers": [
							{ "created_at": "lastday" }
						]
					}
				}
			}
		}
	]
}

Notes:

  • tasks[].data.request.parameters.database - mongodb database name
  • tasks[].data.request.parameters.collection - mongodb collection name
  • tasks[].data.request.parameters.pipeline - for pipeline source data refer to group by and calculate a sum example in mongodb db.collection.aggregate() documentation. Note that in this case with $out collection errand_aggregate_test_result will be replaced with result. replaceKeywords function is applied to all pipeline.
  • tasks[].data.request.parameters.helpers - used to add helpers to beginning of aggregate pipeline where, each object consists of key and value where key contains name of field to apply function in value. Helper functions include:
    • lastday - is used to add date range for matching records from the previous day.
      • lastweek - is used to add date range for matching records from the previous week.

db.collection.createIndex Example


	{
		"tasks": [
			{
				"task": "errand-mongodb",
				"data": {
					"description": "replace-with-task-description",
					"request": {
						"method": "db.collection.createIndex",
						"parameters": {
							"database": "errand_test",
							"collection": "orders",
							"keys": { ... },
							"options": { ... }
						}
					}
				}
			}
		]
	}

Notes:

  • Refer to db.collection.createIndex()
  • tasks[].data.request.parameters.database - mongodb database name
  • tasks[].data.request.parameters.collection - mongodb collection name
  • tasks[].data.request.parameters.keys - db.collection.createIndex() keys
  • tasks[].data.request.parameters.options - db.collection.createIndex() options

replaceKeywords function

The replaceKeywords function is used to replace keywords with variables. Date based keywords replace the entire variable.

replaceKeywords keywords

  • {{_date_minus1_startOf}} replaced with start of yesterday, or new Date(moment().add(-1, 'days').startOf('day')))
  • {{_date_minus8_startOf}} replaced with start of 8 days ago, or new Date(moment().add(-8, 'days').startOf('day')))
  • {{_date_minus1_endOf}} replaced with end of yesterday, or new Date(moment().add(-1, 'days').endOf('day')))