-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnection.js
More file actions
41 lines (34 loc) · 1.2 KB
/
connection.js
File metadata and controls
41 lines (34 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { MongoClient } from 'mongodb';
const uri = 'mongodb+srv://gauravcoding:o4oqY7t4PibERLja@cluster0.obeqo1y.mongodb.net/?retryWrites=true&w=majority';
const client = new MongoClient(uri, { useNewUrlParser: true, useUnifiedTopology: true });
export async function connectToMongoDB() {
try {
await client.connect();
console.log('Connected to MongoDB');
} catch (err) {
console.error('Error connecting to MongoDB:', err);
}
}
export function getInventoryCollection() {
const database = client.db('Inventory_Information');
const collection = database.collection('Inventory');
return collection;
}
export function getLoginCollection() {
const database = client.db('Login_Information');
const collection = database.collection('Credentials');
return collection;
}
export function getRequestCollection() {
const database = client.db('Requests_Information');
const collection = database.collection('Requests');
return collection;
}
export async function closeMongoDBConnection() {
try {
await client.close();
console.log('MongoDB connection closed');
} catch (err) {
console.error('Error closing MongoDB connection:', err);
}
}