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.
Connection
✓ import mongoQueue from 'mongo-queue';
const connection = new mongoQueue.Connection();
✗ const { Connection } = require('mongo-queue');
const connection = new Connection();
The package is written in CoffeeScript and provides a default export. In Node.js, require('mongo-queue') returns the module, which contains Connection, Template, and Worker as properties. Use const mq = require('mongo-queue'); then new mq.Connection(). For ESM, there is no named export; use default import.
Template
✓ import mongoQueue from 'mongo-queue';
class MyJob extends mongoQueue.Template { ... }
✗ const mongoQueue = require('mongo-queue');
class MyJob extends mongoQueue.Template { ... }
Template is a CoffeeScript class; extend it to define job perform() and complete() methods. The library uses CoffeeScript's class inheritance; if using JavaScript, you must call Template.call(this) in constructor or use ES6 class extension which works because CoffeeScript classes are compatible.
Worker
✓ import mongoQueue from 'mongo-queue';
const worker = new mongoQueue.Worker(connection, [MyJob], options);
✗ const { Worker } = require('mongo-queue');
const worker = new Worker(connection, [MyJob], options);
Worker constructor expects connection (instance of Connection), an array of Template subclasses, and an options object. Common mistake: passing job instances instead of classes.
Shows how to create a job template, connect to MongoDB, enqueue a job, and start a worker to process jobs.
import mongoQueue from 'mongo-queue';
class Addition extends mongoQueue.Template {
perform(a, b) {
console.log(a + ' + ' + b + ' = ' + (a + b));
this.complete();
}
}
const connection = new mongoQueue.Connection({
host: 'localhost',
port: 27017,
db: 'test'
});
connection.on('error', err => console.error('Connection error:', err));
connection.on('connected', () => {
console.log('Connected to MongoDB');
// Enqueue a job
connection.enqueue('calculations', 1, 2, (err, job) => {
if (err) return console.error('Enqueue error:', err);
console.log('Job enqueued:', job._id);
});
// Start worker
const worker = new mongoQueue.Worker(connection, [Addition], {
timeout: 1000,
rotate: false,
workers: 3
});
worker.on('error', err => console.error('Worker error:', err));
worker.on('drained', () => console.log('Queue empty'));
worker.on('stopped', () => console.log('Worker stopped'));
worker.poll();
});
connection.on('error', err => console.error('Error:', err));
Errors
Common errors & fixes
ReferenceError: Worker is not defined
Not importing the Worker property from the default export.
fixUse const mongoQueue = require('mongo-queue'); const Worker = mongoQueue.Worker; TypeError: this.complete is not a function
Job class not properly extending mongoQueue.Template or missing method definition.
fixEnsure your job class extends mongoQueue.Template and calls this.complete() correctly. In ES6 classes, you must call super() in constructor if you define one.
MongoError: auth failed
Authentication parameters provided but connection options missing username/password.
fixVerify username and password in the Connection options. Also ensure MongoDB server requires authentication.
Audit
Dependencies
mongodbrequirednative MongoDB driver for database operations