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

Implement collection creation

parent fb9d050c
No related branches found
No related tags found
1 merge request!4Resolve "Configure MongoDB Connection"
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
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