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.

storage
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.

Named export for native MongoDB driver store. ESM only. Requires mongodb package.

import { MongoSessionStore } from 'express-mongodb'

Named export for Mongoose store. ESM and CJS both supported with named exports. Requires mongoose.

import { MongooseSessionStore } from 'express-mongodb'

Factory function that returns a store instance. Useful for dynamic configuration.

import { createMongoSessionStore } from 'express-mongodb'

Factory function for Mongoose store. Accepts same options object.

import { createMongooseSessionStore } from 'express-mongodb'

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 footguns
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).
deprecatedThe legacy callable factory require('express-mongodb')(express) is deprecated. The express argument is ignored. Use named exports instead.
deprecatedOptions 'collection' and 'clear_interval' are deprecated aliases for 'collectionName' and 'clearIntervalSeconds' respectively.
gotchaThe store does not close the MongoDB connection or Mongoose connection. You must manage connection lifecycle separately.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
16 hits · last 30 days
gptbot
3
amazonbot
3
bytedance
2
ahrefsbot
1
Resources