{"id":42943,"library":"keyv-mongodb-store","title":"keyv-mongodb-store","description":"A Keyv store implementation using MongoDB as the backend storage. Current version 0.0.3 (pre-release, experimental). Requires Node >=18, Keyv v5, and MongoDB driver v6. Provides persistent key-value storage with TTL support using MongoDB's native TTL indexes, namespace support, and custom serialization. Supports initialization via MongoDB URI, Database instance, or Collection instance. Fully typed with TypeScript. Alternative to other Keyv stores like keyv-file or keyv-redis for users already invested in MongoDB infrastructure.","status":"active","version":"0.0.3","language":"javascript","source_language":"en","source_url":"https://github.com/snomiao/keyv-mongodb-store","tags":["javascript","keyv","mongodb","storage","store","adapter","key-value","database","nosql","typescript"],"install":[{"cmd":"npm install keyv-mongodb-store","lang":"bash","label":"npm"},{"cmd":"yarn add keyv-mongodb-store","lang":"bash","label":"yarn"},{"cmd":"pnpm add keyv-mongodb-store","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency – this is a store adapter for the Keyv key-value storage library","package":"keyv","optional":false},{"reason":"Peer dependency – required to interact with MongoDB (driver v6)","package":"mongodb","optional":false}],"imports":[{"note":"ESM-only package – CommonJS require will fail. Use ES import.","wrong":"const KeyvMongodbStore = require('keyv-mongodb-store')","symbol":"KeyvMongodbStore","correct":"import { KeyvMongodbStore } from 'keyv-mongodb-store'"},{"note":"Keyv is a separate package, not bundled here. Ensure keyv is installed.","wrong":null,"symbol":"default export (Keyv)","correct":"import Keyv from 'keyv'"},{"note":"TypeScript types are shipped. Use import type for type-only imports.","wrong":null,"symbol":"Types","correct":"import type { Options, Store } from 'keyv'"}],"quickstart":{"code":"import Keyv from 'keyv';\nimport { KeyvMongodbStore } from 'keyv-mongodb-store';\n\nconst store = new KeyvMongodbStore('mongodb://localhost:27017/mydb');\nconst keyv = new Keyv({ store });\n\nawait keyv.set('foo', 'bar');\nconst value = await keyv.get('foo');\nconsole.log(value); // 'bar'\n\nawait keyv.delete('foo');\nawait keyv.clear();\nawait store.close();","lang":"typescript","description":"Basic usage with MongoDB URI: create store, pass to Keyv, set/get/delete/clear and close connection."},"warnings":[{"fix":"Upgrade Node.js to version 18 or later.","message":"Node.js >=18 required. Engine restriction is strict; older Node versions will fail.","severity":"gotcha","affected_versions":"<18"},{"fix":"Install keyv@^5.0.0. Run: npm install keyv@5","message":"Peer dependency keyv v5 is required. Using keyv v4 will cause incompatibility.","severity":"breaking","affected_versions":"keyv versions <5"},{"fix":"Install mongodb@^6.0.0. Run: npm install mongodb@6","message":"Peer dependency mongodb v6 is required. Using mongodb v5 or lower will break.","severity":"breaking","affected_versions":"mongodb <6"},{"fix":"Pin exact version and monitor for breaking changes.","message":"The package is pre-release (v0.0.3). API may change without notice.","severity":"deprecated","affected_versions":">=0.0.1 <1.0.0"},{"fix":"Use get() for immediate expiration check; rely on TTL index for eventual cleanup.","message":"TTL index cleanup runs every 60 seconds. Expired items may remain until cleanup.","severity":"gotcha","affected_versions":"all"},{"fix":"Avoid colon characters in namespace strings.","message":"Namespace is prepended to keys with a colon separator. Ensure your namespace does not contain colons.","severity":"gotcha","affected_versions":"all"},{"fix":"Always specify dbName in URI or use options.dbName to avoid unexpected behavior.","message":"Passing a URI without a path (dbName) may default to 'test' database in MongoDB driver.","severity":"deprecated","affected_versions":"all"}],"env_vars":null,"search_vec":"'0.0.3':17 '18':24 'adapt':90 'alreadi':80 'altern':65 'backend':13 'collect':59 'current':15 'custom':49 'databas':56,94 'driver':29 'experiment':21 'file':73 'fulli':61 'implement':8 'index':45 'infrastructur':84 'initi':52 'instanc':57,60 'invest':81 'javascript':85 'key':34,92 'key-valu':33,91 'keyv':2,6,25,68,72,76,86 'keyv-fil':71 'keyv-mongodb-stor':1 'keyv-redi':75 'like':70 'mongodb':3,10,28,41,54,83,87 'namespac':46 'nativ':43 'node':23 'nosql':95 'persist':32 'pre':19 'pre-releas':18 'provid':31 'redi':77 'releas':20 'requir':22 'serial':50 'storag':14,36,88 'store':4,7,69,89 'support':39,47,51 'ttl':38,44 'type':62 'typescript':64,96 'uri':55 'use':9,40 'user':79 'v5':26 'v6':30 'valu':35,93 'version':16 'via':53","created_at":"2026-06-05T16:57:25.020466+00:00","updated_at":"2026-06-05T16:57:25.020466+00:00","problems":[{"fix":"Use import { KeyvMongodbStore } from 'keyv-mongodb-store' or switch to ESM.","cause":"Attempted to use CommonJS require() on an ESM-only package.","error":"ERR_REQUIRE_ESM"},{"fix":"Ensure URI ends with '/dbname' (e.g., 'mongodb://localhost:27017/mydb').","cause":"Invalid MongoDB URI format, e.g., missing database name.","error":"MongoParseError: Missing expected connection string segment"},{"fix":"Ensure: const keyv = new Keyv({ store: new KeyvMongodbStore('...') })","cause":"Keyv not instantiated correctly – missing new keyword or wrong store type.","error":"TypeError: keyv.set is not a function"}],"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/snomiao/keyv-mongodb-store#readme","github":"https://github.com/snomiao/keyv-mongodb-store","docs":null,"changelog":null,"pypi":null,"npm":"keyv-mongodb-store","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}