Registry / database / fh-mongodb-queue

fh-mongodb-queue

JSON →
library3.3.0jsnpmunverified

A lightweight message queue built on top of MongoDB, forked from mongodb-queue. Version 3.3.0 (unmaintained since 2017). Provides basic queue operations (add, get, ack, ping, clean) with configurable visibility window and delay. Designed for Node.js apps already using MongoDB, offering a simple alternative to dedicated queue systems like RabbitMQ or Redis-backed queues. No support for TTL, dead-letter queues, or message batching. Requires MongoDB driver v2.x or v3.x.

npm install fh-mongodb-queue
INSTALL
IMPORT
SIG · FH-MONGODB-QUEUE
F
fh-mongodb-queue
databasejavascriptv3.3.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
const mongoDbQueue = require('fh-mongodb-queue');
import mongoDbQueue from 'fh-mongodb-queue';
Package is CommonJS only. No default ESM export; using ESM import will fail or require special handling.
MongoClient
const { MongoClient } = require('mongodb');
const MongoClient = require('mongodb').MongoClient;
This is from the mongodb driver, not from fh-mongodb-queue itself.
queue methods (add, get, ack, etc.)
const queue = mongoDbQueue(db, 'my-queue'); queue.add(...);
mongoDbQueue(db, 'my-queue').add(...);
Factory function returns a queue instance. Chaining is possible but not recommended for readability.

Connects to MongoDB, creates a queue, adds and retrieves a message, and acks it. Includes index creation.

const MongoClient = require('mongodb').MongoClient; const mongoDbQueue = require('fh-mongodb-queue'); const con = 'mongodb://localhost:27017/test'; MongoClient.connect(con, { useNewUrlParser: true, useUnifiedTopology: true }, (err, client) => { if (err) return console.error(err); const db = client.db(); const queue = mongoDbQueue(db, 'my-queue'); queue.createIndexes((err) => { if (err) return console.error(err); queue.add('Hello, World!', (err, id) => { if (err) return console.error(err); console.log('Added message id:', id); queue.get({ visibility: 30 }, (err, msg) => { if (err) return console.error(err); console.log('Got message:', msg.payload); queue.ack(msg.ack, (err) => { if (err) return console.error(err); client.close(); }); }); }); }); });
Debug
Known issues
breakingPackage is abandoned; last updated in 2017. No bug fixes or security patches. Use at your own risk.
fix
Migrate to maintained alternatives like @neurocode/mongodb-queue or bull with MongoDB.
affects: >=0.0.0
breakingRelies on MongoDB driver 2.x or 3.x callback API. Modern MongoDB driver 4.x+ uses promises and connection pooling may break this package.
fix
Use mongodb@3.7.4 or downgrade to 2.x. For mongodb@4, manually promisify or use a wrapper.
affects: >=3.0.0
deprecatedCallbacks are the only async pattern supported. No promise or async/await support. Error-first callbacks only.
fix
Wrap in util.promisify or promisify-all to use async/await.
affects: >=0.0.0
gotchaIndex creation (createIndexes) must be called explicitly; it is not automatic. Missing indexes can lead to poor performance.
fix
Call queue.createIndexes() once before using the queue.
affects: >=0.0.0
gotchaMessages are never automatically deleted; acked messages remain in the collection unless queue.clean() is called.
fix
Periodically call queue.clean() to remove processed messages.
affects: >=0.0.0
gotchaThe queue name directly corresponds to a MongoDB collection name; ensure the name meets MongoDB collection naming rules (e.g., no empty string).
fix
Use valid MongoDB collection names, e.g., alphanumeric with underscores.
affects: >=0.0.0
Errors
Common errors & fixes
MongoError: ns not found
Queue collection does not exist or not yet created.
fix
Ensure you call queue.createIndexes() before using the queue, or the queue collection will be created lazily.
TypeError: Cannot read property 'payload' of null
queue.get() returned null when no messages are available, but code assumed an object.
fix
Check if msg is null before accessing properties.
TypeError: queue.add is not a function
Incorrect import or usage; the factory function was not called correctly, or the wrong package was imported.
fix
Use: const queue = mongoDbQueue(db, 'my-queue'); then queue.add(...).
MongoError: cannot add unique index with partialFilterExpression
Old or incompatible MongoDB version (pre-3.2) does not support partialFilterExpression which is used by createIndexes.
fix
Upgrade MongoDB to 3.2+ or manually create indexes without partialFilterExpression.
Upgrade
Version history
3.3.0latest on npm
Audit
Dependencies
mongodbrequiredRequires MongoDB driver (2.x or 3.x) for database connection. Not bundled.
Agent activity
11 hits · last 30 days
node
10
Resources