-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.js
36 lines (30 loc) · 1.32 KB
/
db.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
import { MongoClient, ServerApiVersion } from "mongodb";
import dotenv from "dotenv";
dotenv.config();
const uri = `mongodb+srv://${process.env.DB_USER}:${process.env.DB_PASS}@cluster0.qmbsuxs.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0`;
export const client = new MongoClient(uri, {
serverApi: {
version: ServerApiVersion.v1,
strict: true,
deprecationErrors: true,
}
});
export const userCollection = client.db("nexusDB").collection("users");
export const publisherCollection = client.db("nexusDB").collection("publishers");
export const articleCollection = client.db("nexusDB").collection("articles");
export const tagCollection = client.db("nexusDB").collection("tags");
export const paymentCollection = client.db("nexusDB").collection("payments");
export const connectDB = async () => {
try {
// Connect the client to the server (optional starting in v4.7)
// await client.connect();
// Send a ping to confirm a successful connection
// await client.db("admin").command({ ping: 1 });
// console.log("Successfully Connected to MongoDB!");
} catch (error) {
console.error("Failed to Connect to MongoDB", error);
} finally {
// Ensures that the client will close when you finish/error
// await client.close();
}
};