[COMPASS-6994] MongoDB reports an error when trying to connect it through NodeJS app Created: 01/Jul/23  Updated: 27/Oct/23  Resolved: 03/Jul/23

Status: Closed
Project: Compass
Component/s: Connectivity
Affects Version/s: None
Fix Version/s: No version

Type: Bug Priority: Major - P3
Reporter: Tea Krstic Assignee: Unassigned
Resolution: Gone away Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

OS: Windows
node.js / npm versions: 17.0.32
Additional info: "dependencies":

{ "@types/cors": "^2.8.4", "@types/express": "^4.17.13", "@types/mongodb": "^4.0.7", "@types/mongoose": "^5.11.97", "@types/node": "^17.0.32", "cors": "^2.8.5", "express": "^4.18.2", "express-fileupload": "^1.4.0", "mongodb": "^4.5.0", "mongoose": "^6.3.3" }

Documentation Changes: Not Needed

 Description   

Problem Statement/Rationale

What is going wrong? What action would you like the Engineering team to take?

Please be sure to attach relevant logs with any sensitive data redacted.
How to retrieve logs for: Compass; Shell

Steps to Reproduce

Start mongodb on localhost:27017

After running netstat -an | grep 27017 I get this :

 TCP    127.0.0.1:27017        0.0.0.0:0              LISTENING
  TCP    127.0.0.1:27017        127.0.0.1:57035        ESTABLISHED
  TCP    127.0.0.1:27017        127.0.0.1:57036        ESTABLISHED
  TCP    127.0.0.1:27017        127.0.0.1:57037        ESTABLISHED
  TCP    127.0.0.1:27017        127.0.0.1:57038        ESTABLISHED
  TCP    127.0.0.1:27017        127.0.0.1:57039        ESTABLISHED
  TCP    127.0.0.1:27017        127.0.0.1:57040        ESTABLISHED
  TCP    127.0.0.1:27017        127.0.0.1:57041        ESTABLISHED
  TCP    127.0.0.1:27017        127.0.0.1:57042        ESTABLISHED
  TCP    127.0.0.1:27017        127.0.0.1:57043        ESTABLISHED
  TCP    127.0.0.1:27017        127.0.0.1:57044        ESTABLISHED
  TCP    127.0.0.1:27017        127.0.0.1:57045        ESTABLISHED
  TCP    127.0.0.1:27017        127.0.0.1:57046        ESTABLISHED
  TCP    127.0.0.1:55214        127.0.0.1:27017        TIME_WAIT
  TCP    127.0.0.1:55215        127.0.0.1:27017        TIME_WAIT
  TCP    127.0.0.1:55216        127.0.0.1:27017        TIME_WAIT
  TCP    127.0.0.1:55217        127.0.0.1:27017        TIME_WAIT
  TCP    127.0.0.1:55218        127.0.0.1:27017        TIME_WAIT
  TCP    127.0.0.1:55226        127.0.0.1:27017        TIME_WAIT
  TCP    127.0.0.1:57035        127.0.0.1:27017        ESTABLISHED
  TCP    127.0.0.1:57036        127.0.0.1:27017        ESTABLISHED
  TCP    127.0.0.1:57037        127.0.0.1:27017        ESTABLISHED
  TCP    127.0.0.1:57038        127.0.0.1:27017        ESTABLISHED
  TCP    127.0.0.1:57039        127.0.0.1:27017        ESTABLISHED
  TCP    127.0.0.1:57040        127.0.0.1:27017        ESTABLISHED
  TCP    127.0.0.1:57041        127.0.0.1:27017        ESTABLISHED
  TCP    127.0.0.1:57042        127.0.0.1:27017        ESTABLISHED
  TCP    127.0.0.1:57043        127.0.0.1:27017        ESTABLISHED
  TCP    127.0.0.1:57044        127.0.0.1:27017        ESTABLISHED
  TCP    127.0.0.1:57045        127.0.0.1:27017        ESTABLISHED
  TCP    127.0.0.1:57046        127.0.0.1:27017        ESTABLISHED

Expected Results

Connection should be successful and that should be reported through my backend, when I run command npm run serve:

conn.once('open',()=>{ console.log('Successful connection'); }); 

Actual Results

D:\System files\Desktop\Filip PIA\MEAN-stack\backend>npm run serve

> hello-nodejs-typescript@1.0.0 serve
> node dist/server.js

Express server running on port 4000
D:\System files\Desktop\Filip PIA\MEAN-stack\backend\node_modules\mongoose\lib\connection.js:807
  const serverSelectionError = new ServerSelectionError();
                               ^

MongooseServerSelectionError: connect ECONNREFUSED ::1:27017
    at Connection.openUri (D:\System files\Desktop\Filip PIA\MEAN-stack\backend\node_modules\mongoose\lib\connection.js:807:32)
    at D:\System files\Desktop\Filip PIA\MEAN-stack\backend\node_modules\mongoose\lib\index.js:342:10
    at D:\System files\Desktop\Filip PIA\MEAN-stack\backend\node_modules\mongoose\lib\helpers\promiseOrCallback.js:32:5
    at new Promise (<anonymous>)
    at promiseOrCallback (D:\System files\Desktop\Filip PIA\MEAN-stack\backend\node_modules\mongoose\lib\helpers\promiseOrCallback.js:31:10)
    at Mongoose._promiseOrCallback (D:\System files\Desktop\Filip PIA\MEAN-stack\backend\node_modules\mongoose\lib\index.js:1181:10)
    at Mongoose.connect (D:\System files\Desktop\Filip PIA\MEAN-stack\backend\node_modules\mongoose\lib\index.js:341:20)
    at Object.<anonymous> (D:\System files\Desktop\Filip PIA\MEAN-stack\backend\dist\server.js:17:20)
    at Module._compile (node:internal/modules/cjs/loader:1254:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10) {
  reason: TopologyDescription {
    type: 'Unknown',
    servers: Map(1) {
      'localhost:27017' => ServerDescription

{         _hostAddress: HostAddress \{ isIPv6: false, host: 'localhost', port: 27017 }

,
        address: 'localhost:27017',
        type: 'Unknown',
        hosts: [],
        passives: [],
        arbiters: [],
        tags: {},
        minWireVersion: 0,
        maxWireVersion: 0,
        roundTripTime: -1,
        lastUpdateTime: 528185067,
        lastWriteDate: 0,
        error: MongoNetworkError: connect ECONNREFUSED ::1:27017
            at connectionFailureError (D:\System files\Desktop\Filip PIA\MEAN-stack\backend\node_modules\mongodb\lib\cmap\connect.js:375:20)
            at Socket.<anonymous> (D:\System files\Desktop\Filip PIA\MEAN-stack\backend\node_modules\mongodb\lib\cmap\connect.js:295:22)
            at Object.onceWrapper (node:events:628:26)
            at Socket.emit (node:events:513:28)
            at emitErrorNT (node:internal/streams/destroy:151:8)
            at emitErrorCloseNT (node:internal/streams/destroy:116:3)
            at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
          [Symbol(errorLabels)]: Set(0) {}
        }
      }
    },
    stale: false,
    compatible: true,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    logicalSessionTimeoutMinutes: undefined
  },
  code: undefined
}

Node.js v18.15.0

Additional Notes

Any additional information that may be useful to include.



 Comments   
Comment by Tea Krstic [ 01/Jul/23 ]

Problem fixed: Change in backend connection to database instead of localhost:  mongodb://0.0.0.0:27017 

Comment by PM Bot [ 01/Jul/23 ]

Hello tea.krstic0109@gmail.com, thank you for reaching out to us! The team will review your issue and get back to you soon as soon as possible.

Please review your issue to ensure you've included your environment details and have attached relevant logs (with any sensitive data redacted), so that we're best able to provide you a timely and thorough response. Thanks again!

Generated at Wed Feb 07 22:44:58 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.