-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnection.js
58 lines (43 loc) · 1.59 KB
/
connection.js
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const uri = process.env.DBURL||'mongodb+srv://22cs3003:[email protected]/';
// dotenv.config({path:'C:\Users\agast\OneDrive\Desktop\infernocoders\config.env'});
// import { MongoClient, ServerApiVersion } from "mongodb";
// import dotenv from 'dotenv';
// const client = new MongoClient(uri, {
// useUnifiedTopology: true,
// useNewUrlParser: true,
// });
// (async () => {
// try {
// await client.connect();
// console.log('Connected to the database');
// const db = client.db("Inferno_Coders");
// console.log('Connected to the Inferno_Coders database');
// } catch (err) {
// console.error('Error connecting to the database:', err);
// } finally {
// await client.close();
// }
// })();
// let db = await client.db("Inferno_Coders");
// export default db;
import { MongoClient } from "mongodb";
// import dotenv from 'dotenv';
// const uri = process.env.MONGODB_URI; // Make sure to define MONGODB_URI in your config.env file
// dotenv.config({ path: 'C:\\Users\\agast\\OneDrive\\Desktop\\infernocoders\\config.env' });
const client = new MongoClient(uri, {
useUnifiedTopology: true,
useNewUrlParser: true,
});
const connectToDatabase = async () => {
try {
await client.connect();
console.log('Connected to the database');
const db = client.db("Chuk_Chuk");
console.log('Connected to the Inferno_Coders database');
return db;
} catch (err) {
console.error('Error connecting to the database:', err);
throw err; // Rethrow the error to handle it elsewhere if needed
}
};
export default connectToDatabase;