{"id":42530,"library":"connect-mongodb","title":"connect-mongodb","description":"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.","status":"deprecated","version":"1.1.5","language":"javascript","source_language":"en","source_url":"git://github.com/masylum/connect-mongodb","tags":["javascript"],"install":[{"cmd":"npm install connect-mongodb","lang":"bash","label":"npm"},{"cmd":"yarn add connect-mongodb","lang":"bash","label":"yarn"},{"cmd":"pnpm add connect-mongodb","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required peer dependency for session middleware integration.","package":"connect","optional":false},{"reason":"Required for MongoDB driver classes (Db, Server).","package":"mongodb","optional":false}],"imports":[{"note":"Package does not support ESM import. Must use CommonJS require().","wrong":"import mongoStore from 'connect-mongodb';","symbol":"connect-mongodb (default)","correct":"var mongoStore = require('connect-mongodb');"},{"note":"Must use CommonJS require() for mongodb driver; ESM not supported in this version.","wrong":"import { Db } from 'mongodb';","symbol":"Db","correct":"var Db = require('mongodb').Db;"},{"note":"Variable naming is flexible, but require() style is mandatory.","wrong":"const Server = require('mongodb').Server;","symbol":"Server","correct":"var Server = require('mongodb').Server;"}],"quickstart":{"code":"var connect = require('connect');\nvar Db = require('mongodb').Db;\nvar Server = require('mongodb').Server;\nvar server_config = new Server('localhost', 27017, {auto_reconnect: true, native_parser: true});\nvar db = new Db('test', server_config, {});\nvar mongoStore = require('connect-mongodb');\n\nconnect.createServer(\n  connect.bodyParser(),\n  connect.cookieParser(),\n  connect.session({\n    cookie: {maxAge: 60000 * 20},\n    secret: 'foo',\n    store: new mongoStore({db: db})\n  })\n);","lang":"javascript","description":"Basic usage: create a MongoDB connection, instantiate the session store, and attach it to Connect/Express session middleware."},"warnings":[{"fix":"Update code to use Db/Server instances. Refer to README example.","message":"Version 1.* is not compatible with 0.* versions. Must pass a MongoDB connection or server configuration instead of string parameters.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Use mongodb.Db and mongodb.Server directly. Use mongoose.connection.db for Mongoose connections.","message":"Requires node-mongodb-native classes; does not accept connection strings or Mongoose connections.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Migrate to connect-mongo for modern Express.js support.","message":"Project is abandoned; no updates since 2012. Does not support Express 4.x or newer Connect versions.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Consider setting up a TTL index on the sessions collection manually via MongoDB shell or use connect-mongo.","message":"Session expiry is handled by reapInterval (polling). No TTL index support - manual cleanup required.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Set native_parser: false if encountering parser errors.","message":"Native parser option (native_parser: true) may cause issues on some systems.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'0':32 '1.1.5':21 '2012':27 'applic':74 'authent':43 'autom':61 'back':14 'cleanup':62 'collect':46 'configur':41 'connect':2,5,38,58,69 'connect-mongo':68 'connect-mongodb':1,4 'connect/express.js':13 'custom':45 'explicit':36 'express.js':73 'featur':55 'incompat':30 'index':65 'javascript':75 'known':48 'lack':53 'latest':24 'like':56 'modern':54,72 'mongo':70 'mongodb':3,6,9,18,37 'mongoos':57 'name':47 'nativ':19 'node':17 'node-mongodb-n':16 'requir':35 'reus':59 'server':40 'session':10 'simplic':51 'sinc':26 'store':11 'supersed':66 'support':42 'ttl':64 'unmaintain':25 'version':20,33 'via':63","created_at":"2026-06-05T16:55:26.035074+00:00","updated_at":"2026-06-05T16:55:26.035074+00:00","problems":[{"fix":"Run 'npm install connect' in your project.","cause":"connect-mongodb lists connect as a peer dependency but does not install it automatically.","error":"Error: Cannot find module 'connect'"},{"fix":"Ensure that the db and server_config options are passed correctly (instances, not strings).","cause":"Session object is missing or malformed when connecting to MongoDB.","error":"TypeError: Cannot call method 'toString' of undefined"},{"fix":"Use 'var Server = require('mongodb').Server;' and ensure mongodb npm package is installed.","cause":"Failed to require('mongodb').Server properly.","error":"ReferenceError: Server is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"git://github.com/masylum/connect-mongodb","github":"git://github.com/masylum/connect-mongodb","docs":null,"changelog":null,"pypi":null,"npm":"connect-mongodb","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database","security"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}