Registry / database / mongodb-queue-up

mongodb-queue-up

JSON →
library5.5.0jsnpmunverified

A lightweight message queue implementation built on MongoDB, forked from mongodb-queue@4 to add support for MongoDB Node.js Driver v4, v5, v6, and v7. Version 5.5.0 is stable and feature-complete. Key differentiators: zero external dependencies beyond MongoDB driver, simple callback-based API, message visibility timeout and delay configuration, built-in indexing and cleanup. Compared to alternatives like Bull or Bee-Queue, it leverages existing MongoDB infrastructure without additional services.

npm install mongodb-queue-up
INSTALL
IMPORT
SIG · MONGODB-QUEUE-UP
M
mongodb-queue-up
databasejavascriptv5.5.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import mongoDbQueue from 'mongodb-queue-up'
const mongoDbQueue = require('mongodb-queue-up')
ESM default import; CommonJS require also works.
MongoClient
import { MongoClient } from 'mongodb'
const MongoClient = require('mongodb').MongoClient
Use named import from mongodb driver.
Queue
import type { Queue } from 'mongodb-queue-up'
Type import for TypeScript users.

Creates a MongoDB-backed queue, adds a message, retrieves it, and acknowledges it using async/await.

import { MongoClient } from 'mongodb'; import mongoDbQueue from 'mongodb-queue-up'; const url = process.env.MONGO_URL ?? 'mongodb://localhost:27017/'; const client = new MongoClient(url); async function main() { await client.connect(); const db = client.db('test'); const queue = mongoDbQueue(db, 'my-queue'); // Create indexes (run once) await queue.createIndexes(); // Add a message const id = await queue.add('Hello, World!'); console.log('Added message id:', id); // Get a message const msg = await queue.get(); if (msg) { console.log('Got message:', msg.payload); // Ack the message await queue.ack(msg.ack); console.log('Acked message'); } await client.close(); } main().catch(console.error);
Debug
Known issues
gotchaDefault visibility timeout is 30 seconds. Messages not acked within this window reappear in the queue.
fix
Set a higher visibility option when creating the queue: mongoDbQueue(db, 'queue', { visibility: 60 })
affects: >=1.0.0
deprecatedThe callback-style API is deprecated; prefer async/await or Promises.
fix
Use await queue.add(...) instead of queue.add(..., callback).
affects: >=5.0.0
breakingUpgraded from mongodb-queue@4: dropped support for MongoDB driver v2 and v3.
fix
Use mongodb-queue@4 for MongoDB v3 driver, mongodb-queue@3 for v2 driver.
affects: >=5.0.0
gotchaThe queue name is used as the MongoDB collection name. Avoid special characters that are invalid in MongoDB collection names.
fix
Use alphanumeric queue names only.
affects: >=1.0.0
gotchaProcessed messages are not automatically deleted. Use queue.clean() to remove them.
fix
Call queue.clean() periodically or after processing.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: mongoDbQueue is not a function
Using default import with CommonJS require in an ESM-only context or vice versa.
fix
Use correct import: import mongoDbQueue from 'mongodb-queue-up' in ESM, or const mongoDbQueue = require('mongodb-queue-up') in CommonJS.
MongoError: E11000 duplicate key error collection: test.my-queue index: ...
The queue collection has a unique index but messages are being duplicated. Usually due to incorrect ack handling.
fix
Ensure each message is acked only once. Use queue.ack(msg.ack) and handle errors.
TypeError: Cannot read properties of undefined (reading 'id')
queue.get() returned undefined (no messages available) and you tried to access msg.id.
fix
Check if msg is not null/undefined: if (msg) { console.log(msg.id); }
Upgrade
Version history
5.5.0latest on npm
Audit
Dependencies
mongodbrequiredPeer dependency: requires MongoDB Node.js driver v4, v5, v6, or v7
Agent activity
2 hits · last 30 days
node
2
Resources
mongodb-queue-up — npm install mongodb-queue-up · libregistry