Registry / database / connect-mongostore

connect-mongostore

JSON →
library0.1.4jsnpmunverified

MongoDB session store for Connect and Express (v0.1.4). Supports replica sets with detailed configuration, SSL connections, and optional Mongoose integration. It works with Express 3.x and 4.x (with express-session). The package has a slow release cadence (last update), and requires manual invocation as a factory function. Compared to connect-mongo, it offers replica set support out of the box but is less maintained.

npm install connect-mongostore
INSTALL
IMPORT
SIG · CONNECT-MONGOSTORE
C
connect-mongostore
databasejavascriptv0.1.4
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.

MongoStore
const MongoStore = require('connect-mongostore')(session);
const MongoStore = require('connect-mongostore');
This package exports a factory function that must be called with the session middleware (express.session or express-session) to produce a store constructor.
MongoStore
const MongoStore = require('connect-mongostore')(express);
const { MongoStore } = require('connect-mongostore');
For Express 3.x, pass the express object itself (which includes session).
MongoStore instance
new MongoStore({ db: 'sessions', host: 'localhost', port: 27017 })
new MongoStore({ url: 'mongodb://localhost:27017/sessions' })
Options are passed as object properties, not a single 'url' string (unlike connect-mongo). Use 'db' for database name, not 'url'.

Express 4.x session store setup with connect-mongostore, using environment variables for configuration.

const express = require('express'); const session = require('express-session'); const MongoStore = require('connect-mongostore')(session); const app = express(); app.use(session({ secret: process.env.SESSION_SECRET || 'default-secret', resave: false, saveUninitialized: true, store: new MongoStore({ db: 'myapp-sessions', host: process.env.MONGO_HOST || 'localhost', port: parseInt(process.env.MONGO_PORT || '27017'), collection: 'sessions' }) })); app.get('/', (req, res) => { req.session.views = (req.session.views || 0) + 1; res.send('Views: ' + req.session.views); }); app.listen(3000);
Debug
Known issues
gotchaThe package must be invoked as a factory: require('connect-mongostore')(session), not just require().
fix
Use the pattern: const MongoStore = require('connect-mongostore')(session); where session is the session middleware instance (express-session or express.session).
affects: >=0.0.0
gotchaThe 'db' option can be a string (database name) or an object with replica set configuration. Passing a MongoClient URI string may not work as expected.
fix
Provide the database name as a string, or an object with 'name' and 'servers' properties for replica sets. Do not use a MongoDB connection URI.
affects: >=0.0.0
deprecatedThe last release (0.1.4) is years old; the package may not work with newer mongodb driver versions or Node.js versions.
fix
Consider migrating to a maintained alternative like connect-mongo or connect-mongodb-session.
affects: >=0.0.0
gotchaBy default, sessions are not stringified (stringify: false). Session objects are stored as-is, which may break with plain JavaScript objects if they contain non-serializable types.
fix
Set 'stringify: true' in options to ensure JSON serialization, or ensure session objects are plain objects.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: MongoStore is not a constructor
Requiring connect-mongostore without calling the factory function with a session module.
fix
Use const MongoStore = require('connect-mongostore')(session); where session is express-session (or express for 3.x).
Error: Invalid db option. Expected string or object.
Passing a MongoDB connection URI string instead of the database name or a replica set configuration object.
fix
Pass the database name as a string to 'db', e.g., { db: 'myapp-sessions' }. Do not use a full URI like 'mongodb://localhost:27017/db'.
MongoError: connect ECONNREFUSED 127.0.0.1:27017
MongoDB server not running on default host/port, or connection options are incorrect.
fix
Ensure MongoDB is running and accessible. Use environment variables to set host and port, e.g., { host: process.env.MONGO_HOST || 'localhost', port: process.env.MONGO_PORT || 27017 }.
Upgrade
Version history
0.1.4latest on npm
Audit
Dependencies
mongodbrequiredNative MongoDB driver for database operations
Agent activity
10 hits · last 30 days
node
8
OpenAI (training)
1
Resources
connect-mongostore — npm install connect-mongostore · libregistry