Registry / storage / fast-mongoose-job-queue

fast-mongoose-job-queue

JSON →
library1.0.14jsnpmunverified

Simple job queue implementation using Mongoose and MongoDB. v1.0.14, stable, maintained fork of mongoose-jobqueue compatible with Mongoose v5+. Uses ES6 Promises, no external deps besides Mongoose, implements MongoDB indexes and .lean() for performance. Offers queue operations: add, checkout, ack, ping, cleanup. Slightly different from original: no lodash, ES6 spread, arrow functions, CosmoDB sort support.

npm install fast-mongoose-job-queue
INSTALL
IMPORT
SIG · FAST-MONGOOSE-JOB-
F
fast-mongoose-job-queue
storagejavascriptv1.0.14
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 mongooseJobQueue = require('mongoose-jobqueue');
import mongooseJobQueue from 'mongoose-jobqueue';
Package does not ship ESM; use CommonJS require. Named import not supported.
default (ESM with bundler)
import mongooseJobQueue from 'mongoose-jobqueue';
import { mongooseJobQueue } from 'mongoose-jobqueue';
If using TypeScript or bundler with esModuleInterop, default import may work. Named import will fail.
module function call result
const queue = mongooseJobQueue(mongoose, 'queueName');
const queue = new mongooseJobQueue(mongoose, 'queueName');
The exported function is a factory, not a constructor. Do not use 'new'.

Connects to MongoDB, creates a job queue instance, adds a job, then checks out and acknowledges a job.

const mongoose = require('mongoose'); const mongooseJobQueue = require('mongoose-jobqueue'); mongoose.connect(process.env.MONGODB_URI ?? 'mongodb://localhost:27017/test'); const queue = mongooseJobQueue(mongoose, 'my-queue'); // Add a job queue.add({ message: 'Hello', priority: 1 }).then(job => { console.log('Added job:', job._id); }).catch(err => { console.error('Add error:', err); }); // Checkout a job queue.checkout().then(job => { if (job) { console.log('Got job:', job._id, job.payload); // Do work... queue.ack(job.ack).then(() => console.log('Job acknowledged')); } else { console.log('No jobs in queue'); } }).catch(err => { console.error('Checkout error:', err); });
Debug
Known issues
breakingVersion 1.0.0 dropped dependency on lodash and Bluebird, uses ES6 Promises and native spread. Code expecting lodash methods on queue objects will break.
fix
Upgrade to >=1.0.0 and replace any usage of lodash methods (_.pluck, etc.) with native JavaScript.
affects: <1.0.0
breakingRequires Mongoose >=5.11.3. Older Mongoose versions are incompatible.
fix
Upgrade Mongoose to >=5.11.3.
affects: <5.11.3
gotchaThe exported module is a factory function, not a constructor. Using 'new' will not throw but will produce unexpected results.
fix
Do not use 'new'; call the function directly: mongooseJobQueue(mongoose, queueName).
affects: >=0
gotchaJob payload must be an object or primitive. Complex types like Date may be serialized as strings by MongoDB.
fix
Ensure payloads are JSON-serializable. For Dates, use ISO strings.
affects: >=0
gotchaThe package does not support ESM import directly; requires CommonJS require. Some bundlers may not resolve default export correctly.
fix
Use require() or configure bundler to handle CommonJS modules.
affects: >=0
Errors
Common errors & fixes
Cannot find module 'mongoose-jobqueue'
Package installed as 'fast-mongoose-job-queue' on npm, but required as 'mongoose-jobqueue'.
fix
Install the correct package: npm install fast-mongoose-job-queue. Then require('fast-mongoose-job-queue') or create an alias.
TypeError: mongooseJobQueue is not a constructor
Using 'new' on the imported factory function.
fix
Call the function without 'new': const queue = mongooseJobQueue(mongoose, 'queueName');
MongooseError: Model not found: JobQueue
The queue name used in checkout/ack does not match the name provided when creating the queue.
fix
Ensure the same queue name string is passed to both mongooseJobQueue(mongoose, name) and when using queue operations.
TypeError: Cannot read property 'collection' of undefined
Mongoose connection not established before creating queue instance.
fix
Call mongoose.connect() (or ensure connection is open) before mongooseJobQueue().
Upgrade
Version history
1.0.14latest on npm
Audit
Dependencies
mongooserequiredPeer dependency: requires Mongoose >=5.11.3 for MongoDB interaction
Agent activity
16 hits · last 30 days
node
14
OpenAI (training)
1
Resources
fast-mongoose-job-queue — npm install fast-mongoose-job-queue · libregistry