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.
KeyvMongodbStore
✓ import { KeyvMongodbStore } from 'keyv-mongodb-store'
✗ const KeyvMongodbStore = require('keyv-mongodb-store')
ESM-only package – CommonJS require will fail. Use ES import.
default export (Keyv)
✓ import Keyv from 'keyv'
Keyv is a separate package, not bundled here. Ensure keyv is installed.
Types
✓ import type { Options, Store } from 'keyv'
TypeScript types are shipped. Use import type for type-only imports.
Basic usage with MongoDB URI: create store, pass to Keyv, set/get/delete/clear and close connection.
import Keyv from 'keyv';
import { KeyvMongodbStore } from 'keyv-mongodb-store';
const store = new KeyvMongodbStore('mongodb://localhost:27017/mydb');
const keyv = new Keyv({ store });
await keyv.set('foo', 'bar');
const value = await keyv.get('foo');
console.log(value); // 'bar'
await keyv.delete('foo');
await keyv.clear();
await store.close();
Debug
Known issues
gotchaNode.js >=18 required. Engine restriction is strict; older Node versions will fail.fixUpgrade Node.js to version 18 or later.
affects: <18
breakingPeer dependency keyv v5 is required. Using keyv v4 will cause incompatibility.fixInstall keyv@^5.0.0. Run: npm install keyv@5
affects: keyv versions <5
breakingPeer dependency mongodb v6 is required. Using mongodb v5 or lower will break.fixInstall mongodb@^6.0.0. Run: npm install mongodb@6
affects: mongodb <6
deprecatedThe package is pre-release (v0.0.3). API may change without notice.fixPin exact version and monitor for breaking changes.
affects: >=0.0.1 <1.0.0
gotchaTTL index cleanup runs every 60 seconds. Expired items may remain until cleanup.fixUse get() for immediate expiration check; rely on TTL index for eventual cleanup.
affects: all
gotchaNamespace is prepended to keys with a colon separator. Ensure your namespace does not contain colons.fixAvoid colon characters in namespace strings.
affects: all
deprecatedPassing a URI without a path (dbName) may default to 'test' database in MongoDB driver.fixAlways specify dbName in URI or use options.dbName to avoid unexpected behavior.
affects: all
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Attempted to use CommonJS require() on an ESM-only package.
fixUse import { KeyvMongodbStore } from 'keyv-mongodb-store' or switch to ESM. MongoParseError: Missing expected connection string segment
Invalid MongoDB URI format, e.g., missing database name.
fixEnsure URI ends with '/dbname' (e.g., 'mongodb://localhost:27017/mydb').
TypeError: keyv.set is not a function
Keyv not instantiated correctly – missing new keyword or wrong store type.
fixEnsure: const keyv = new Keyv({ store: new KeyvMongodbStore('...') }) Audit
Dependencies
keyvrequiredPeer dependency – this is a store adapter for the Keyv key-value storage library
mongodbrequiredPeer dependency – required to interact with MongoDB (driver v6)