-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.js
37 lines (31 loc) · 877 Bytes
/
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
37
const { Schema, default: mongoose } = require("mongoose");
const membershipSchema = new Schema(
{
discord_id: { type: String, unique: true },
ntnui_no: { type: String, unique: true },
has_valid_group_membership: Boolean,
ntnui_contract_expiry_date: String,
},
{
strict: true,
minimize: true,
autoIndex: true,
timestamps: true,
versionKey: false,
toJSON: { getters: true },
toObject: { getters: true },
}
);
const Membership = mongoose.model("Membership", membershipSchema);
// Connect to the database
async function connectDB() {
try {
await mongoose.connect(process.env.DB_CONNECTION);
console.log("Connected to MongoDB");
} catch (err) {
console.error("Error connecting to MongoDB:", err);
}
}
// Call the connectDB function to establish the connection
connectDB();
module.exports = { Membership };