Registry / database / keyv-mongodb-store

keyv-mongodb-store

JSON →
library0.0.3jsnpmunverified

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.

npm install keyv-mongodb-store
INSTALL
IMPORT
SIG · KEYV-MONGODB-STORE
K
keyv-mongodb-store
databasejavascriptv0.0.3
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.

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.
fix
Upgrade Node.js to version 18 or later.
affects: <18
breakingPeer dependency keyv v5 is required. Using keyv v4 will cause incompatibility.
fix
Install 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.
fix
Install 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.
fix
Pin 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.
fix
Use 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.
fix
Avoid colon characters in namespace strings.
affects: all
deprecatedPassing a URI without a path (dbName) may default to 'test' database in MongoDB driver.
fix
Always 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.
fix
Use 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.
fix
Ensure 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.
fix
Ensure: const keyv = new Keyv({ store: new KeyvMongodbStore('...') })
Upgrade
Version history
0.0.3latest on npm
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)
Agent activity
11 hits · last 30 days
node
10
Resources
keyv-mongodb-store — npm install keyv-mongodb-store · libregistry