We are making a movie database and the server suddenly stopped working. I deleted the original code and rewrote it and this is where the problem comes at. Here what the teacher said
Solving mongoose.connect issues
If you are using the latest versions of Node.js with mongoose, and you get a connection refused ECONNREFUSED error message when connecting your app to the database, then you might need to change localhost to 127.0.0.1 in your mongoose.connect database connection string:
mongoose.connect(‘mongodb://127.0.0.1:27017/your_database_name_here’)
Also, in the currently newest mongoose versions you don’t need to pass the options object as the second argument to the mongoose.connect method.
Therefore, when using the newest mongoose versions, your mongoose.connect call can look just like shown above, without adding an object with options such as useNewUrlParser, useUnifiedTopology, useCreateIndex, or useFindAndModify.
I tried both what the teacher said and what’s on mongoose website
bellow is my index.js code.
mongoose.connect('mongodb://127.0.0.1:27017/your_database_name_here')
mongoose.connect('mongodb://127.0.0.1:27017/test')
.then(() => {
console.log("Connection OPEN")
})
.catch(error => {
console.log("OH NO error")
console.log(error)
})```
this is what the terminal said in response
```$ node index.js
OH NO error
MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
at _handleConnectionErrors (C:Users\Colt The Web Developer Bootcamp 2023redonode_m
odulesmongooselibconnection.js:909:11)
at NativeConnection.openUri (C:Users\Colt The Web Developer Bootcamp 2023redonode_
modulesmongooselibconnection.js:860:11) {
reason: TopologyDescription {
type: 'Unknown',
servers: Map(1) { '127.0.0.1:27017' => [ServerDescription] },
stale: false,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
setName: null,
maxElectionId: null,
maxSetVersion: null,
commonWireVersion: 0,
logicalSessionTimeoutMinutes: null
},
code: undefined
}```
I tired redoing the code and then I created a new folder and reinstalled the npms