I set up a MongoDB database to use with a simple node.js project I created many months ago and it was working fine back then. I can still connect to it and query it from the command line just fine (using the mongo CLI) but cannot seem to connect to it from within node. When I use this code to connect:
I found this similar question when searching for solutions, but I don’t think their fix makes sense for me. I have a very simple setup with mongo and node running on the same machine. I don’t entirely remember why I set up replication, but it was only because of some sort of warning I had encountered back when I set this up. The contents of the database are not important, so I don’t mind if the data gets destroyed, I’d just like to be able to connect to mongo from node again. Thanks in advance for any help!
I would still appreciate an explanation if anyone can enlighten me as to why this change is necessary. My system doesn’t seem to have any trouble resolving localhost to 127.0.0.1, so I’m baffled that this works.
This makes sense to me. I guess there must have been an update to node.js that changed localhost from 127.0.0.1 to ::1. Although when I change the mongo client to mongodb://[::1]/my-project?replicaSet=rs0 I do get a different error message: