Registry / database / connect-mongodb

connect-mongodb

JSON →
library1.1.5jsnpmunverified

Connect-MongoDB is a MongoDB session store for Connect/Express.js, backed by node-mongodb-native. Version 1.1.5 is the latest (unmaintained since 2012) and is incompatible with 0.* versions. It requires explicit MongoDB connection or server configuration, supporting authentication and custom collection names. Known for its simplicity but lacks modern features like Mongoose connection reuse and automated cleanup via TTL indexes. Superseded by connect-mongo for modern Express.js applications.

npm install connect-mongodb
INSTALL
IMPORT
SIG · CONNECT-MONGODB
C
connect-mongodb
databasejavascriptv1.1.5
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.

connect-mongodb (default)
var mongoStore = require('connect-mongodb');
import mongoStore from 'connect-mongodb';
Package does not support ESM import. Must use CommonJS require().
Db
var Db = require('mongodb').Db;
import { Db } from 'mongodb';
Must use CommonJS require() for mongodb driver; ESM not supported in this version.
Server
var Server = require('mongodb').Server;
const Server = require('mongodb').Server;
Variable naming is flexible, but require() style is mandatory.

Basic usage: create a MongoDB connection, instantiate the session store, and attach it to Connect/Express session middleware.

var connect = require('connect'); var Db = require('mongodb').Db; var Server = require('mongodb').Server; var server_config = new Server('localhost', 27017, {auto_reconnect: true, native_parser: true}); var db = new Db('test', server_config, {}); var mongoStore = require('connect-mongodb'); connect.createServer( connect.bodyParser(), connect.cookieParser(), connect.session({ cookie: {maxAge: 60000 * 20}, secret: 'foo', store: new mongoStore({db: db}) }) );
Debug
Known issues
breakingVersion 1.* is not compatible with 0.* versions. Must pass a MongoDB connection or server configuration instead of string parameters.
fix
Update code to use Db/Server instances. Refer to README example.
affects: >=1.0.0
gotchaRequires node-mongodb-native classes; does not accept connection strings or Mongoose connections.
fix
Use mongodb.Db and mongodb.Server directly. Use mongoose.connection.db for Mongoose connections.
affects: >=1.0.0
deprecatedProject is abandoned; no updates since 2012. Does not support Express 4.x or newer Connect versions.
fix
Migrate to connect-mongo for modern Express.js support.
affects: >=1.0.0
gotchaSession expiry is handled by reapInterval (polling). No TTL index support - manual cleanup required.
fix
Consider setting up a TTL index on the sessions collection manually via MongoDB shell or use connect-mongo.
affects: >=1.0.0
gotchaNative parser option (native_parser: true) may cause issues on some systems.
fix
Set native_parser: false if encountering parser errors.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'connect'
connect-mongodb lists connect as a peer dependency but does not install it automatically.
fix
Run 'npm install connect' in your project.
TypeError: Cannot call method 'toString' of undefined
Session object is missing or malformed when connecting to MongoDB.
fix
Ensure that the db and server_config options are passed correctly (instances, not strings).
ReferenceError: Server is not defined
Failed to require('mongodb').Server properly.
fix
Use 'var Server = require('mongodb').Server;' and ensure mongodb npm package is installed.
Upgrade
Version history
1.1.5latest on npm
Audit
Dependencies
connectrequiredRequired peer dependency for session middleware integration.
mongodbrequiredRequired for MongoDB driver classes (Db, Server).
Agent activity
33 hits · last 30 days
node
30
OpenAI (training)
1
Resources
connect-mongodb — npm install connect-mongodb · libregistry