question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MongoStore.create({}) options 'client' and 'clientPromise' not compatible with Mongoose version 6

See original GitHub issue
  • I’m submitting a … [x] bug report [ ] feature request [ ] question about the decisions made in the repository [ ] question about how to use this project

  • Summary Mongoose has been updated to version 6. When using client or clientPromise in MongoStore.create({ }), sessions are no longer saved to database.

  • Other information (e.g. detailed explanation, stack traces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
gkostovcommented, Feb 25, 2022

This example demonstrates how it’s done with Mongoose 6 https://github.com/jdesboeufs/connect-mongo/blob/master/example/mongoose.js . Though I prefer a bit simpler approach (one that’s also closer to what was there with previous versions):

...
store: MongoStore.create({
    client: mongoose.connection.getClient(),
...
0reactions
vishwajeetsinh-arhamcommented, Dec 19, 2022

this works for me

const MongoStore = require('connect-mongo');

=================Main Code=============================

 const store = MongoStore.create({
    mongoUrl: dbUrl,
    secret: 'thisshouldbeabettersecret',
    touchAfter: 24 * 60 * 60
})

================= End Main Code=============================

store.on('error', function(e){
    console.log('Session Store Error', e)
})

const sessionConfig = {
    store,
    // change your default name
    name: 'session',
    secret: 'thisshouldbeabettersecret!', 
    resave: false, 
    saveUninitialized: true,
    cookie:{
        httpOnly: true,
        // don't use this on development it's break thing
        // secure: true,
        expires: Date.now() + 1000 * 60 * 60  * 24 * 7,
        maxAge: 1000 * 60 * 60  * 24 * 7
    }
}
app.use(session(sessionConfig))
Read more comments on GitHub >

github_iconTop Results From Across the Web

MongoStore: Cannot Init Client. Not accepting mongoose ...
Turns out the mongooseConnection parameter to the MongoStore constructor ... the getClient() function to help make that happen - like this:
Read more >
Mongoose v6.8.1: Connecting to MongoDB
You can connect to MongoDB with the mongoose.connect() method. ... you should also disable the autoCreate option and use createCollection() to create capped ......
Read more >
Connect-mongo NPM | npm.io
Create a new connection from a MongoDB connection string · Re-use an existing native MongoDB driver client promise.
Read more >
I'm trying to connect mongoDB to my web app but it shows ...
A snippet of code showing how you are creating the connection including your MongoDB connection string with any password or hostname details ...
Read more >
Day 45: PassportJS + Express + MongoDB? - Jamal J8 Ahmed
The connect-mongo packages has some cryptography options so maybe there is ... that must be provided for the Mongostore.create() methods.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found