MongoDB collection as a crontab / job queue. Current stable version is 1.9.0, released under ISC license, actively maintained. It uses the official MongoDB Node.js driver (v6) and atomic MongoDB commands to ensure safe job processing in clustered environments. Key differentiator: simple document-based scheduling using a `sleepUntil` field, with built-in lock and retry mechanisms. TypeScript types included. Note: not to be confused with Agenda or similar libraries.
npm install mongodb-cronNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Connects to MongoDB, creates a cron worker that processes jobs from a collection, inserts a job, and stops after 10 seconds.
Ensure you pass a valid collection object: `db.collection('jobs')`.Always use async functions: `onDocument: async (doc) => { ... }`Keep mongodb-cron at ~1.9.0 if you must use older MongoDB driver versions.
Use `sleepUntil` with a Date object for one-time or deferred jobs. For recurring jobs, re-insert a new job after completion.
Explicitly set `sleepUntil` to a future date or null to avoid immediate processing.
Use `collection.insertOne(doc)` or `collection.insertMany([doc])`.
Ensure you pass `db.collection('yourCollectionName')` to the `collection` option.Use `import { MongoCron } from 'mongodb-cron'` in ESM, or switch to CommonJS (`type: commonjs` in package.json).