Registry / storage / neutrinos-mongodb-session-store

neutrinos-mongodb-session-store

JSON →
library0.0.2-beta.1jsnpmunverified

A MongoDB session store for Express.js, built on the official mongodb driver v4. It provides a simple way to persist session data in MongoDB. Currently at version 0.0.2-beta.1, it is in early beta with an unstable API. It relies on mongodb ^4.8.0 as a peer dependency and ships TypeScript definitions. Compared to connect-mongo, it has fewer features and less community adoption, but offers direct integration with the modern MongoDB driver.

npm install neutrinos-mongodb-session-store
INSTALL
IMPORT
SIG · NEUTRINOS-MONGODB-
N
neutrinos-mongodb-session-store
storagejavascriptv0.0.2-beta.1
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.

MongoDBSessionStore
import MongoDBSessionStore from 'neutrinos-mongodb-session-store'
const MongoDBSessionStore = require('neutrinos-mongodb-session-store')
Default export; package is ESM-only and does not support require().
MongoDBSessionStore
import MongoDBSessionStore from 'neutrinos-mongodb-session-store'
import { MongoDBSessionStore } from 'neutrinos-mongodb-session-store'
Named import will fail; this package uses a default export.
session
import session from 'express-session'
import session from 'neutrinos-mongodb-session-store'
The store is used with express-session; do not confuse the package.

Shows how to create a MongoDB session store, connect to MongoDB, and use it with express-session in an Express app.

import MongoDBSessionStore from 'neutrinos-mongodb-session-store'; import session from 'express-session'; import express from 'express'; import { MongoClient } from 'mongodb'; const app = express(); const client = new MongoClient(process.env.MONGO_URI ?? 'mongodb://localhost:27017'); await client.connect(); const store = new MongoDBSessionStore({ client: client, dbName: 'sessions', collectionName: 'sessions' }); app.use(session({ secret: process.env.SESSION_SECRET ?? 'keyboard cat', resave: false, saveUninitialized: false, store: store })); app.get('/', (req, res) => { req.session.views = (req.session.views || 0) + 1; res.send(`Views: ${req.session.views}`); }); app.listen(3000);
Debug
Known issues
breakingThe package is at version 0.0.2-beta.1; the API may change without notice between minor versions.
fix
Pin to exact version and monitor releases for breaking changes.
affects: <1.0.0
deprecatedThe constructor option 'client' must be a MongoClient instance from the mongodb driver v4. Using v5 or v6 client may cause incompatibility.
fix
Use mongodb ^4.8.0 peer dependency; upgrade driver only after verifying compatibility.
affects: >=0.0.2-beta.1
gotchaThe store does not support callbacks; it uses promises. Using async/await is recommended.
fix
Ensure your application uses async/await or promises when interacting with store methods.
affects: >=0.0.2-beta.1
gotchaSession expiration is handled by MongoDB TTL index on the 'expires' field. If you drop or alter the index, sessions will never expire.
fix
Do not modify the TTL index created by the store on the sessions collection.
affects: >=0.0.2-beta.1
Errors
Common errors & fixes
MongoDBSessionStore is not a constructor
Using require() with the default ESM-only export.
fix
Use import MongoDBSessionStore from 'neutrinos-mongodb-session-store'.
TypeError: Cannot read properties of undefined (reading 'collection')
The MongoClient instance not passed or client not connected before creating store.
fix
Ensure client.connect() is called before instantiating MongoDBSessionStore.
MongoError: dbName option is required
Missing or invalid dbName in constructor options.
fix
Provide a valid dbName string when creating the store instance.
Upgrade
Version history
0.0.2-beta.1latest on npm
Audit
Dependencies
mongodbrequiredRequired as a peer dependency to interact with MongoDB.
Agent activity
13 hits · last 30 days
node
12
Amazon
1
Resources
neutrinos-mongodb-session-store — npm install neutrinos-mongodb-session-store · libregistry