From aaf3b48318f3ffaa07e5cdeaa8701a46f35acff6 Mon Sep 17 00:00:00 2001
From: strokh24 <Rokas.Stankunas@Student.Reutlingen-University.DE>
Date: Sun, 6 Oct 2024 17:49:57 +0200
Subject: [PATCH] Implement collection creation

---
 mongodb.js | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/mongodb.js b/mongodb.js
index e69de29..37662f0 100644
--- a/mongodb.js
+++ b/mongodb.js
@@ -0,0 +1,22 @@
+const { MongoClient, Db } = require('mongodb');
+const url = 'mongodb://localhost:27017/todo';
+
+async function createCollections() {
+  	try {
+		const client = new MongoClient(url);
+		await client.connect();
+
+		// Check if the "todo" database exists and create it if not
+		const db = client.db('todo');
+		await db.createCollection('users'); // Check if collection "users" exists and create it if it doesn't exist
+		await db.createCollection('todos'); // Check if collection "todos" exists and create it if it doesn't exist
+		await db.createCollection('global'); // Check if collection "global" exists and create it if it doesn't exist
+
+		console.log('Collections created successfully!');
+		await client.close();
+	} catch (error) {
+		console.error('Error creating collections:', error);
+	}
+}
+
+createCollections();
\ No newline at end of file
-- 
GitLab