Registry / database / cache-manager-mongoose-v2

cache-manager-mongoose-v2

JSON →
library1.0.0jsnpmunverified

Mongoose store for node-cache-manager v1.0.0, enabling MongoDB caching via an existing Mongoose connection. Stable, low-traffic package designed as an alternative to node-cache-manager-mongodb, with support for custom models, TTL, and Mongoose connection reuse. Key differentiator: leverages your existing Mongoose instance, avoiding redundant connections.

npm install cache-manager-mongoose-v2
INSTALL
IMPORT
SIG · CACHE-MANAGER-MONG
C
cache-manager-mongoose-v2
databasejavascriptv1.0.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 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); }); });
Debug
Known issues
gotchaOptions hash requires a 'mongoose' key, not 'connection' for default connection. If using mongoose.createConnection(), pass the connection explicitly via 'connection' option.
fix
Pass mongoose instance as { mongoose: mongoose }, or provide a custom model to bypass.
affects: >=0.0.0
gotchaTTL=0 means cache forever (no expiry), not immediate expiry. This differs from some other stores where 0 means no cache.
fix
Set TTL to 0 for no expiry, or omit for default 60 seconds.
affects: >=0.0.0
deprecatedThe package uses Mongoose .findOneAndUpdate() which is deprecated in newer Mongoose versions (6+). May cause deprecation warnings.
fix
Use a custom model or upgrade to a version that uses newer Mongoose API.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: mongoose.model is not a function
You passed a Mongoose connection object instead of the Mongoose instance.
fix
Ensure you pass the mongoose module itself: { mongoose: require('mongoose') }
Cannot read property 'model' of undefined
You omitted the mongoose option entirely.
fix
Add mongoose: require('mongoose') to the options object.
MongooseCache is already registered
Multiple cache instances with the same default model name 'MongooseCache'.
fix
Use custom model or set a different modelName option for each cache instance.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
cache-managerrequiredPeer dependency: this store is used with node-cache-manager
mongooserequiredRequired: provides the model and connection for caching
Agent activity
37 hits · last 30 days
node
33
Resources
cache-manager-mongoose-v2 — npm install cache-manager-mongoose-v2 · libregistry