DB lags/freezes doesn't work with discord bot in JavaScript

Hi,
I run a Discord bot that’s in about 40,000 servers. I am using the mongoClient, I tried using atlas and a local server. During my development, everything works fine, but when I run the production bot which is in 40,000 servers and 40 shards, the code just essentially stops right where my query to database. It doesn’t error or anything, the code just stops running. Not sure what the issue is as I always used mongo… Could it be because of my shards? or not sure.

// How I connect
await new Promise((resolve) => {
mongodbClient.connect((err) => {
if (err != undefined) throw err;
console.log([${new Date().toLocaleString()}] [Mongo] Connected.);
client.db = mongodbClient.db(‘bot’);

resolve();

});
});

// My database query task function

function databaseTask(
database,
collection,
method,
id,
initialize,
…queries
) {
const col = database.collection(collection);
const existingDocument = await col.findOne({ id });
const defaultCollectionValues = defaultDatabaseValues[collection];

if (existingDocument === null && initialize)
await col.insertOne({
id,
…defaultCollectionValues
});

return method === ‘reset’
? col.updateOne(
{ id },
{
$set: Object.fromEntries(
queries[0].map((key) => {
if (!key.includes(’.’))
return [key, defaultCollectionValues[key]];

          let value = defaultCollectionValues;

          for (const property of key.split('.')) value = value[property];

          return [key, value];
        })
      )
    }
  )
: col[method](...queries);

}