Registry /
database / cache-manager-mongoose-v2
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 mongooseStore = require('cache-manager-mongoose');
const cache = cacheManager.caching({ store: mongooseStore, mongoose: mongoose });
✗ import mongooseStore from 'cache-manager-mongoose';
This package is CJS-only; no ESM default export exists. Use require().
default
✓ const cacheManager = require('cache-manager');
✗ const cacheManager = require('node-cache-manager');
The package name is 'cache-manager', not 'node-cache-manager'.
default
✓ const mongooseStore = require('cache-manager-mongoose');
const cache = cacheManager.caching({ store: mongooseStore, mongoose: mongoose });
✗ const cache = cacheManager.caching({ store: 'cache-manager-mongoose', mongoose: mongoose });
The store must be the function/object, not a string.
Connects to MongoDB via Mongoose, creates a cache store, caches a value, then retrieves it.
const mongoose = require('mongoose');
const cacheManager = require('cache-manager');
const mongooseStore = require('cache-manager-mongoose');
mongoose.connect('mongodb://127.0.0.1/test');
const cache = cacheManager.caching({
store: mongooseStore,
mongoose: mongoose,
ttl: 300
});
// Usage
cache.set('key', { data: 'value' }, (err) => {
if (err) console.error(err);
cache.get('key', (err, result) => {
console.log(result);
});
});
Errors
Common errors & fixes
TypeError: mongoose.model is not a function
You passed a Mongoose connection object instead of the Mongoose instance.
fixEnsure you pass the mongoose module itself: { mongoose: require('mongoose') } Cannot read property 'model' of undefined
You omitted the mongoose option entirely.
fixAdd mongoose: require('mongoose') to the options object. MongooseCache is already registered
Multiple cache instances with the same default model name 'MongooseCache'.
fixUse custom model or set a different modelName option for each cache instance.
Audit
Dependencies
cache-managerrequiredPeer dependency: this store is used with node-cache-manager
mongooserequiredRequired: provides the model and connection for caching