• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

209
Views
Cómo conectarse a mongoDB desde mecanografiado

Recibo un error al intentar agregar la conexión mongo a la solicitud

La propiedad 'dbClient' no existe en el tipo 'Request<ParamsDictionary>'.

Me gustaría tener disponible la conexión sin tener que añadirla a todas mis rutas.

Gracias por tu ayuda

Aquí está mi fragmento de código

 const mongoUri = process.env.MONGO_URI ? process.env.MONGO_URI : ""; const mongoClient = new MongoClient(mongoUri); async function createMongoConnecion() { try { await mongoClient.connect(); console.log("connected"); } catch (err) { console.log("Error connecting to mongo: " + err); } finally { console.log("Connected to mongo successfully!"); } } app.use(async function (req, res, next) { req.dbClient = mongoClient; next(); }); routes.push(new SearchRoutes(app));
almost 3 years ago · Santiago Trujillo
1 answers
Answer question

0

Paso 1:

En la carpeta raíz, cree el archivo types/express/index.d.ts con este contenido:

 declare global { namespace Express { interface Request { dbClient: object; } } }

Paso 2

Actualice el archivo tsconfig.json :

 { "compilerOptions": { "typeRoots": ["./types"] } }
almost 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error