arunbandari / mongo-gui

A web-based MongoDB graphical user interface
http://20.106.238.56:4321/
MIT License
280 stars 84 forks source link

MongoServerSelectionError: connect ECONNREFUSED localhost:27017 #132

Open deflexable opened 4 months ago

deflexable commented 4 months ago

i install npm i start mongodb server (on macos using brew services start mongodb-community) i started the server with node server i visited http://localhost:4321/ i viewed a collection - it loads correctly the first time but when i try viewing another collection, it keeps spinning and after spinning for a while it shows a toast saying MongoServerSelectionError: connect ECONNREFUSED and displayed a box and text below it saying This collection doesn't have any documents

below shows the error logged on the server:

MongoServerSelectionError: connect ECONNREFUSED localhost:27017
    at Timeout._onTimeout (/Users/aoamacsplace/Documents/dirty/mongo-gui-master/node_modules/mongodb/lib/core/sdam/topology.js:438:30)
    at listOnTimeout (node:internal/timers:569:17)
    at process.processTimers (node:internal/timers:512:7) {
  reason: TopologyDescription {
    type: 'Single',
    setName: null,
    maxSetVersion: null,
    maxElectionId: null,
    servers: Map(1) { 'localhost:27017' => [ServerDescription] },
    stale: false,
    compatible: true,
    compatibilityError: null,
    logicalSessionTimeoutMinutes: null,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    commonWireVersion: 17
  }
}
deflexable commented 4 months ago

after almost a day of debgging, i was able to fix it by:

  1. updating mongodb to "^6.5.0"
  2. changing from line 57 all the way to line 66 to this
        proms.push(dataAccessAdapter.ConnectToDb(
          dbName
        ).command({ collStats: collection.name })
          .then((stats) => {
            collection.stats = {
              count: stats.count,
              size: stats.totalSize
            };
          }));
deflexable commented 4 months ago

i have up-to 75 collections in a database.

executing db.collection.stats() simultaneously at Promise.all for this amount of collections causes mongodb to crash and exit

changing to db.command({ collStats: collection.name }) fixes it

although this issue doesn't occur if you have 0 - 50 collections

db.collection.stats() has also been deprecated and removed