Skip to content
Snippets Groups Projects
Commit cebc490e authored by Rokas Stankunas's avatar Rokas Stankunas
Browse files

Removed creation of collections in mongodb.js

parent a7c2c85c
No related branches found
No related tags found
1 merge request!4Resolve "Configure MongoDB Connection"
Pipeline #15556 passed
...@@ -6,19 +6,9 @@ async function connectDB() { ...@@ -6,19 +6,9 @@ async function connectDB() {
// Connect using the MongoDB URI from environment variables // Connect using the MongoDB URI from environment variables
const conn = await mongoose.connect(process.env.MONGO_URI || "mongodb://127.0.0.1:27017/todo_app"); const conn = await mongoose.connect(process.env.MONGO_URI || "mongodb://127.0.0.1:27017/todo_app");
console.log(`MongoDB connected: ${conn.connection.host}`); console.log(`MongoDB connected: ${conn.connection.host}`);
// Get the database object from the connection
const db = conn.connection.db;
// Check if the collections exist and create them if not
await db.createCollection('users');
await db.createCollection('todos');
await db.createCollection('global');
console.log('Collections created successfully!');
} catch (err) { } catch (err) {
console.error(`Error: ${err.message}`); console.error(`Error: ${err.message}`);
process.exit(1); // Exit the process with failure if the connection or collection creation fails process.exit(1); // Exit the process with failure if the connection fails
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment