Uploaded image for project: 'Compass '
  1. Compass
  2. COMPASS-6994

MongoDB reports an error when trying to connect it through NodeJS app

    • Type: Icon: Bug Bug
    • Resolution: Gone away
    • Priority: Icon: Major - P3 Major - P3
    • No version
    • Affects Version/s: None
    • Component/s: Connectivity
    • None
    • Environment:
    • Not Needed

      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.

            Assignee:
            Unassigned Unassigned
            Reporter:
            tea.krstic0109@gmail.com Tea Krstic
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: