MongoNetworkError: connection 2 to 18.185.185.208:27017 closed

Viewed 34
const keyv = new Keyv(process.env.mongo);
wait(3000)

keyv.on('error', err => console.error('Keyv connection error:', err));
const delay = ms => new Promise(res => setTimeout(res, ms));

function wait(ms){
   var start = new Date().getTime();
   var end = start;
   while(end < start + ms) {
     end = new Date().getTime();
  }
}

wait(3000)
const inventory = new Keyv(process.env.mongo, { collection: 'inventory' })
wait(3000)
  
const daily = new Keyv(process.env.mongo, { collection: 'daily' })
wait(3000)

const wallet = new Keyv(process.env.mongo, { collection: 'wallet' })
wait(3000)

const bank = new Keyv(process.env.mongo, { collection: 'bank' })
wait(3000)

const location = new Keyv(process.env.mongo, { collection: 'location' })
wait(3000)

const userbase = new Keyv(process.env.mongo, { collection: 'userbase' })
wait(3000)

const travelcount = new Keyv(process.env.mongo, { collection: 'travelcount' })

I've got a MongoDB database using keyv to store data, however, I keep getting the following connection error: MongoNetworkError: connection 2 to 18.185.185.208:27017 closed Does anyone, by any chance, know what prevents it from connecting and/or how to fix it?

1 Answers

robertklep's solution gives the following error:


/home/runner/FeatureTesting/node_modules/mongodb/lib/utils.js:419
                    throw error;
                    ^

MongoNetworkError: connection 1 to 18.185.185.208:27017 closed
    at Connection.onClose (/home/runner/FeatureTesting/node_modules/mongodb/lib/cmap/connection.js:135:19)
    at TLSSocket.<anonymous> (/home/runner/FeatureTesting/node_modules/mongodb/lib/cmap/connection.js:62:46)
    at TLSSocket.emit (node:events:390:28)
    at TLSSocket.emit (node:domain:475:12)
    at node:net:687:12
Emitted 'error' event on Keyv instance at:
    at KeyvMongo.<anonymous> (/home/runner/FeatureTesting/node_modules/keyv/src/index.js:64:46)
    at KeyvMongo.emit (node:events:390:28)
    at KeyvMongo.emit (node:domain:475:12)
Related