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

627
Views
¿Por qué no puedo conectar mongodb usando el nodo js?

Inicié mi servidor mongodb y el software realmente puede conectarlo.
Imagen de inicio de Mongodb
GIF de error
Mi código de nodo js es

 mongoose.connect("mongodb://localhost:27017/chat", { useNewUrlParser: true }).catch(err => console.log(err));

y me da el error

 MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoNetworkError: connection 0 to localhost:27017 closed at Socket.<anonymous> (D:\Web开发\fake-chatroom\server\node_modules\mongodb\lib\core\connection\connection.js:439:9) at Object.onceWrapper (events.js:422:26) at Socket.emit (events.js:315:20) at TCP.<anonymous> (net.js:673:12)] at Pool.<anonymous> (D:\Web开发\fake-chatroom\server\node_modules\mongodb\lib\core\topologies\server.js:438:11) at Pool.emit (events.js:315:20) at D:\Web开发\fake-chatroom\server\node_modules\mongodb\lib\core\connection\pool.js:562:14 at D:\Web开发\fake-chatroom\server\node_modules\mongodb\lib\core\connection\pool.js:995:11 at callback (D:\Web开发\fake-chatroom\server\node_modules\mongodb\lib\core\connection\connect.js:75:5) at D:\Web开发\fake-chatroom\server\node_modules\mongodb\lib\core\connection\connect.js:101:9 at _callback (D:\Web开发\fake-chatroom\server\node_modules\mongodb\lib\core\connection\connection.js:328:7) at Connection.errorHandler (D:\Web开发\fake-chatroom\server\node_modules\mongodb\lib\core\connection\connection.js:343:7) at Object.onceWrapper (events.js:422:26) at Connection.emit (events.js:315:20) at Socket.<anonymous> (D:\Web开发\fake-chatroom\server\node_modules\mongodb\lib\core\connection\connection.js:437:12) at Object.onceWrapper (events.js:422:26) at Socket.emit (events.js:315:20) at TCP.<anonymous> (net.js:673:12)
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Según la imagen que publicó, mongodb está escuchando en el puerto predeterminado, 27017. Su código está intentando abrir una conexión al puerto 28019, que es la causa del error.

Utilice el número de puerto predeterminado en su código:

 mongoose.connect("mongodb://localhost:27017/chat", { useNewUrlParser: true }).catch(err => console.log(err));
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!