To migrate the library from V3 to V4, re-install the dependencies.
Use your package manager (npm example shown):
npm uninstall connect-mongo
npm uninstall @types/connect-mongo
npm install connect-mongo
Next step is to import the dependencies
Javascript:
const MongoStore = require('connect-mongo');Typescript:
import MongoStore from 'connect-mongo';Create the store using MongoStore.create(options) instead of new MongoStore(options)
app.use(session({
secret: 'foo',
store: MongoStore.create(options)
}));For the options, you should make the following changes:
- Change
urltomongoUrl - Change
collectiontocollectionNameif you are using it - Keep
clientPromiseif you are using it mongooseConnectionhas been removed. Please update your application code to use eithermongoUrl,clientorclientPromise- To reuse an existing mongoose connection retreive the mongoDb driver from you mongoose connection using
Connection.prototype.getClient()and pass it to the store in theclient-option. - Remove
fallbackMemoryoption and if you are using it, you can import from:
const session = require('express-session');
app.use(session({
store: isDev ? new session.MemoryStore() : MongoStore.create(options)
}));You can also take a look at example directory for example usage.