Registry / database / cache-manager-mongodb

cache-manager-mongodb

JSON →
library0.3.0jsnpmunverified

MongoDB store for node-cache-manager (v0.3.0). This package integrates MongoDB as a persistent caching backend for the node-cache-manager module. It provides a simple API for get, set, del, and wrap operations with full Promise support. The store supports configurable collection names, compression, pool size, and auto-reconnect. Unlike in-memory or Redis stores, it leverages MongoDB for durable, shared caching across multiple processes or servers. The package has low release activity and is considered stable but not actively developed.

npm install cache-manager-mongodb
INSTALL
IMPORT
SIG · CACHE-MANAGER-MONG
C
cache-manager-mongodb
databasejavascriptv0.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 mongoStore = require('cache-manager-mongodb')
✗ import mongoStore from 'cache-manager-mongodb'
This package is CommonJS-only and does not provide ESM exports.
cacheManager
✓ const cacheManager = require('cache-manager')
✗ const mongoStore = require('cache-manager-mongodb'); const cache = mongoStore()
You must use node-cache-manager's caching() function with the store option, not call mongoStore directly.
MongoStore
✓ const mongoStore = require('cache-manager-mongodb')
✗ const { MongoStore } = require('cache-manager-mongodb')
There is no named export; the whole module is the store object.

Shows how to create a MongoDB-backed cache store, set, get, and delete a value using Promises.

const cacheManager = require('cache-manager'); const mongoStore = require('cache-manager-mongodb'); const mongoCache = cacheManager.caching({ store: mongoStore, uri: process.env.MONGO_URI || 'mongodb://localhost:27017/cacheDb', options: { collection: 'cacheManager', compression: false, poolSize: 5, autoReconnect: true }, ttl: 60 }); mongoCache.set('myKey', 'myValue', 60) .then(() => mongoCache.get('myKey')) .then(result => { console.log(result); // 'myValue' return mongoCache.del('myKey'); }) .catch(err => console.error(err));
Debug
Known issues
breakingVersion 0.2.0 switched from callbacks to full Promise support; old callback-style code will break.
fix
Replace callbacks with .then()/.catch() or use async/await.
affects: >=0.2.0
gotchaThe package has no TypeScript types; using it in a TypeScript project may require custom type declarations.
fix
Install @types/cache-manager-mongodb if available, or declare module manually.
affects: *
gotchaMongoDB connection URI must include credentials if authentication is enabled; otherwise connection fails silently.
fix
Ensure URI contains username:password@host:port/dbname.
affects: *
deprecatedThe package is not actively maintained; no updates since 2019. It may not work with newer MongoDB drivers or node-cache-manager versions.
fix
Consider alternatives like cache-manager-ioredis or cache-manager-mongoose.
affects: >=0.3.0
Errors
Common errors & fixes
Error: The collection parameter must be a string, or an object with a collection property
Passing an invalid options object without 'collection' property or wrong type.
fix
Provide options.collection as a string: { collection: 'myCache' }
TypeError: mongoStore is not a constructor
Attempting to use mongoStore() directly instead of passing it as a store option to cacheManager.caching()
fix
Use cacheManager.caching({ store: mongoStore, ... })
Upgrade
Version history
0.3.0latest on npm
Audit
Dependencies
node-cache-managerrequiredPeer dependency; this package provides a MongoDB store for the cache manager infrastructure.
mongodbrequiredRequired to interact with MongoDB; typically the 'mongodb' driver is a dependency of this package.
Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
cache-manager-mongodb — npm install cache-manager-mongodb · libregistry