-2

Before updating nodejs my code was working fine but after updating my nodejs version. whenever i am connecting to the server(localhost), after connecting in a few seconds it gives me this error. enter image description here

and in vs code console it gives enter image description here

and this is my code: enter image description here

I am trying to connect to my local database using the localhost server.

VIPIN
  • 1
  • 1
  • Does this answer your question? [Can't connect to MongoDB 6.0 Server locally using Nodejs driver](https://stackoverflow.com/questions/74609210/cant-connect-to-mongodb-6-0-server-locally-using-nodejs-driver) – Wernfried Domscheit Dec 27 '22 at 07:46
  • Please don't paste screenshots, use formatted text. See https://meta.stackoverflow.com/questions/285551/why-should-i-not-upload-images-of-code-data-errors – Wernfried Domscheit Dec 27 '22 at 07:47

1 Answers1

0

The error message indicates the application is attempting to connect to the IPv6 address ::1, i.e. localhost.

The code you have shows uses IPv4 localhost address 127.0.0.1, and appears to connect successfully at that point.

Some time later, another connection is attempted that goes to the IPv6 address.

This suggests that both:

  • something later uses localhost instead of an IP, and the operating system resolves that to ::1
  • mongod is not listening on the IPv6 address

To fix this, you could do one or more of:

  • modify the mongod.conf so that it listens on ::1 in addition to 127.0.0.1
  • search the code to find where localhost is used and change it to the IP4 address
  • modify the local operating system so localhost only resolves to an IP4 address (this is probably a bad idea)
Joe
  • 25,000
  • 3
  • 22
  • 44