{"id":44486,"library":"cache-manager-mongoose","title":"cache-manager-mongoose","description":"Mongoose store for node-cache-manager that uses an existing Mongoose connection to cache data in MongoDB. Version 1.0.1 is stable, with infrequent releases. Key differentiators: allows custom Mongoose models, supports TTL-based expiration via MongoDB TTL index, and lets you reuse existing connections instead of creating a new one. Compared to other MongoDB cache stores, it integrates tightly with Mongoose schemas.","status":"active","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/disjunction/node-cache-manager-mongoose","tags":["javascript","cache","mongoose","cache manager"],"install":[{"cmd":"npm install cache-manager-mongoose","lang":"bash","label":"npm"},{"cmd":"yarn add cache-manager-mongoose","lang":"bash","label":"yarn"},{"cmd":"pnpm add cache-manager-mongoose","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency; provides caching API that this store implements","package":"cache-manager","optional":false}],"imports":[{"note":"Package is CJS-only; no default ESM export. Use require (or use createRequire in ESM).","wrong":"import mongooseStore from 'cache-manager-mongoose';","symbol":"default","correct":"const mongooseStore = require('cache-manager-mongoose');"},{"note":"Used to create a cache instance with mongooseStore as the store.","symbol":"cacheManager","correct":"const cacheManager = require('cache-manager');"},{"note":"Required to pass to cache-manager options when using a Mongoose connection.","symbol":"mongoose","correct":"const mongoose = require('mongoose');"}],"quickstart":{"code":"const mongoose = require('mongoose');\nconst cacheManager = require('cache-manager');\nconst mongooseStore = require('cache-manager-mongoose');\n\nmongoose.connect('mongodb://localhost/test');\n\nconst cache = cacheManager.caching({\n  store: mongooseStore,\n  mongoose: mongoose,\n  ttl: 600\n});\n\nasync function run() {\n  await cache.set('myKey', 'myValue', { ttl: 300 });\n  const value = await cache.get('myKey');\n  console.log('Cached value:', value);\n  await cache.del('myKey');\n}\n\nrun().catch(console.error);","lang":"javascript","description":"Shows basic usage: connect Mongoose, create a cache manager with mongoose store, set/get/delete a value."},"warnings":[{"fix":"Pass mongoose: require('mongoose') or your existing connection instance to the caching options.","message":"Must provide 'mongoose' option (mongoose instance) unless providing a custom 'model'","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Pass connection: yourConnectionObject in addition to mongoose: mongoose to the caching options.","message":"When using mongoose.createConnection(), you must explicitly pass the connection in options as 'connection'","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use a very large TTL or set 'ttl' option to Infinity/null if supported by cache-manager.","message":"TTL of 0 used to mean forever but behavior may change in future versions","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.0.1':24 'allow':32 'base':39 'cach':2,10,19,61,70,72 'cache-manager-mongoos':1 'compar':57 'connect':17,50 'creat':53 'custom':33 'data':20 'differenti':31 'exist':15,49 'expir':40 'index':44 'infrequ':28 'instead':51 'integr':64 'javascript':69 'key':30 'let':46 'manag':3,11,73 'model':35 'mongodb':22,42,60 'mongoos':4,5,16,34,67,71 'new':55 'node':9 'node-cache-manag':8 'one':56 'releas':29 'reus':48 'schema':68 'stabl':26 'store':6,62 'support':36 'tight':65 'ttl':38,43 'ttl-base':37 'use':13 'version':23 'via':41","created_at":"2026-06-07T12:50:21.941988+00:00","updated_at":"2026-06-07T12:50:21.941988+00:00","problems":[{"fix":"Ensure options passed to cacheManager.caching include mongoose: require('mongoose')","cause":"Mongoose instance not provided or incorrect options object","error":"TypeError: Cannot read properties of undefined (reading 'model')"},{"fix":"Provide a unique modelName option to each cache instance, e.g., modelName: 'MyCache'","cause":"Multiple cache instances with same modelName or default name conflict","error":"MongooseError: Model 'MongooseCache' already exists"},{"fix":"Check package is installed and required as const mongooseStore = require('cache-manager-mongoose'); (not destructured)","cause":"Store not passed correctly or require('cache-manager-mongoose') returns undefined","error":"Error: store must be an object with methods get, set, del, etc."}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/disjunction/node-cache-manager-mongoose#readme","github":"https://github.com/disjunction/node-cache-manager-mongoose","docs":null,"changelog":null,"pypi":null,"npm":"cache-manager-mongoose","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database","storage"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}