-2

It's my first time using MongoDB, Git and Note.js. I tried to start server on cmd by this command: node server.js.
At the beginning it turns out that the server is running on port 3000, but then error:

Error connecting to database: MongooseServerSelectionError: connect ECONNREFUSED ::1:27017
at _handleConnectionErrors (C:\Users\Me\Documents\myprjct\node_modules\mongoose\lib\connection.js:792:11)
at NativeConnection.openUri (C:\Users\Me\Documents\myprjct\node_modules\mongoose\lib\connection.js:767:11)
at runNextTicks (node:internal/process/task_queues:60:5)
at listOnTimeout (node:internal/timers:538:9)
at process.processTimers (node:internal/timers:512:7) {
reason: TopologyDescription {
type: 'Unknown',
servers: Map(1) { 'localhost:27017' => [ServerDescription] },
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
setName: null,
maxElectionId: null,
maxSetVersion: null,
commonWireVersion: 0,
logicalSessionTimeoutMinutes: null
},
code: undefined
}

I wrote the name of the DB correctly and I stopped the port and start again, but that didn't helped. I want to run my DB.

greybeard
  • 2,249
  • 8
  • 30
  • 66
Elnur
  • 1

1 Answers1

-1

There are 2-3 points needs to check

  • Verify MongoDB installation: Ensure that MongoDB is installed on your machine and running properly. You can try running the mongod command in a separate terminal window to start the MongoDB server.
  • Check MongoDB server status: Open a new terminal window and run the command mongo to open the MongoDB shell. Then, run the db.runCommand({ serverStatus: 1 }) command to check the server status. Make sure that the server is up and running without any issues.
  • Check MongoDB connection string: In your server.js file, verify that the MongoDB connection string is correct. The connection string
    should specify the correct hostname (localhost in your case) and port (27017 by default). Double-check the syntax and ensure that there are no typos or missing characters.
hiren207
  • 184
  • 6