Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

290
Views
Mongoose and connect-mongo

I am using mongoose for managing relationships between data and I am trying to use connect-mongo to store specific sessions in the database.

It looks like that we need to connect twice to the db, one with mongoose and another one with connect-mongo.

I am using the following code to initialise a connection for mongoose

await mongoose.connect(this._connectionUrl, this._connectionOptions);

Initialising a new store every time (not sure if I am correct regarding code initialisation).

app.use(session({
            // secret: config.sessionSecretKey,
            secret: "secretkey",
            resave: true,
            saveUninitialized: true,
            cookie: { maxAge: 19 * 60000 }, // store for 19 minutes
            store: MongoStore.create({
                mongoUrl: this._connectionUrl,
                mongoOptions: this._connectionOptions // See below for details
            })
        }))

Is there any way that I can pass the connection from mongoose to mongo-connect Store?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

i'm lookin for a solution too and just read this on the "migration guide" of connect-mongo

For the options, you should make the following changes:

Change url to mongoUrl Change collection to collectionName if you are using it Keep clientPromise if you are using it mongooseConnection has been removed. Please update your application code to use either mongoUrl, client or clientPromise 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 the client-option. Remove fallbackMemory option and if you are using it,

and there's this example https://github.com/jdesboeufs/connect-mongo/blob/master/example/mongoose.js

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!