Registry / storage / express-mongodb

express-mongodb

JSON →
library1.0.0jsnpmunverified

MongoDB-backed session store for express-session. Current stable version is 1.0.0, released in 2025. It targets Node.js >=22 and supports both native MongoDB driver and Mongoose adapters. A modern rewrite of the original Express 2/Mongoose store, it provides ESM and CommonJS compatibility, TypeScript types, and a simple API. Key differentiators include a pluggable adapter pattern, automatic TTL index creation, and deprecated migration helpers for legacy code.

npm install express-mongodb
INSTALL
IMPORT
SIG · EXPRESS-MONGODB
E
express-mongodb
storagejavascriptv1.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.

MongoSessionStore
import { MongoSessionStore } from 'express-mongodb'
import MongoSessionStore from 'express-mongodb'
Named export for native MongoDB driver store. ESM only. Requires mongodb package.
MongooseSessionStore
import { MongooseSessionStore } from 'express-mongodb'
const MongooseSessionStore = require('express-mongodb').MongooseSessionStore
Named export for Mongoose store. ESM and CJS both supported with named exports. Requires mongoose.
createMongoSessionStore
import { createMongoSessionStore } from 'express-mongodb'
Factory function that returns a store instance. Useful for dynamic configuration.
createMongooseSessionStore
import { createMongooseSessionStore } from 'express-mongodb'
Factory function for Mongoose store. Accepts same options object.

Shows how to set up a session store using native MongoDB driver with express-session.

import express from 'express'; import session from 'express-session'; import { MongoClient } from 'mongodb'; import { MongoSessionStore } from 'express-mongodb'; const app = express(); const client = new MongoClient(process.env.MONGO_URI ?? 'mongodb://localhost:27017/test'); await client.connect(); app.use(session({ secret: process.env.SESSION_SECRET ?? 'default-secret', resave: false, saveUninitialized: false, store: new MongoSessionStore({ client, dbName: 'test', collectionName: 'session' }) })); app.get('/', (req, res) => { req.session.views = (req.session.views || 0) + 1; res.json({ views: req.session.views }); }); app.listen(3000, () => console.log('Server running on port 3000'));
Debug
Known issues
breakingBreaking change in version 1.0.0: Non-callable class instances (MongoSessionStore, MongooseSessionStore) replace the legacy callable factory. Old require('express-mongodb')(express) pattern no longer works correctly (express argument is ignored).
fix
Use new MongoSessionStore(options) or new MongooseSessionStore(options) directly with express-session.
affects: >=1.0.0
deprecatedThe legacy callable factory require('express-mongodb')(express) is deprecated. The express argument is ignored. Use named exports instead.
fix
Import MongoSessionStore or MongooseSessionStore from the package and instantiate with options.
affects: >=1.0.0
deprecatedOptions 'collection' and 'clear_interval' are deprecated aliases for 'collectionName' and 'clearIntervalSeconds' respectively.
fix
Use 'collectionName' and 'clearIntervalSeconds' instead.
affects: >=1.0.0
gotchaThe store does not close the MongoDB connection or Mongoose connection. You must manage connection lifecycle separately.
fix
Call client.close() or mongoose.disconnect() after you no longer need the session store.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: express_mongodb_1.default is not a constructor
Using default import when only named exports exist.
fix
Import named export: import { MongoSessionStore } from 'express-mongodb'
Error: Cannot find module 'express-mongodb'
Missing package installation or wrong import path.
fix
Run 'npm install express-mongodb' and ensure the import statement is correct.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
express-sessionrequiredPeer dependency required to use the session store
mongodboptionalRequired for native MongoDB store
mongooseoptionalRequired for Mongoose store
Agent activity
28 hits · last 30 days
node
24
OpenAI (training)
1
Resources
express-mongodb — npm install express-mongodb · libregistry