Small fix

This commit is contained in:
2026-01-27 15:05:04 +01:00
parent ca07a0ed3b
commit 41949fe596
12 changed files with 61 additions and 86 deletions
+3 -8
View File
@@ -1,11 +1,10 @@
const { MongoClient, ServerApiVersion } = require('mongodb');
const { mongodb } = require("./config.json");
const {MongoClient, ServerApiVersion} = require('mongodb');
const {mongodb} = require("./config.json");
let dbClient;
async function connectToDatabase() {
if (!dbClient) {
// Create a new MongoClient only once
dbClient = new MongoClient(mongodb, {
serverApi: {
version: ServerApiVersion.v1,
@@ -13,15 +12,11 @@ async function connectToDatabase() {
deprecationErrors: true,
}
});
await dbClient.connect();
console.log("Connected to MongoDB!");
await dbClient.db("admin").command({ ping: 1 });
await dbClient.db("admin").command({ping: 1});
console.log("Pinged your deployment. You successfully connected to MongoDB!");
}
// Return the existing connection if already connected
return dbClient;
}