Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

291
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda