From b057bcfa3e13f224f9be992857da296d7b616d9d Mon Sep 17 00:00:00 2001 From: Matt Gunter Date: Thu, 16 Jan 2025 19:18:30 -0500 Subject: [PATCH] getting app to work cleanly with mongoose --- backend/src/database.ts | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/backend/src/database.ts b/backend/src/database.ts index e763344..4b6529a 100644 --- a/backend/src/database.ts +++ b/backend/src/database.ts @@ -12,11 +12,13 @@ class Database { } async connect() { + //improve the logger message @12:12 + logger.info('Connecting to the database', this.mongodbUri); if (this.mongodbUri) await updateDotenv({ MONGODB_URI: this.mongodbUri }); try { this.mongoose = await mongoose.connect(this.mongodbUri, { - //useNewUrlParser: true, + //useNewUrlParser: true, // 12:08 could be used later //useUnifiedTopology: true, socketTimeoutMS: 90000, // Set the socket timeout (e.g., 60 seconds) connectTimeoutMS: 60000, // Connection timeout (e.g., 30 seconds) @@ -220,13 +222,9 @@ class Database { // Create indexes for faster queries 🔍 teamMemberSchema.index({ team: 1, member: 1 }, { unique: true }); - // Create models 📦 - mongoose.model('Team', teamSchema); - mongoose.model('Member', memberSchema); - mongoose.model('TeamMember', teamMemberSchema); - mongoose.model('Counter', counterSchema); // Ensure Counter model is registered here - console.log('Created Counter model'); - mongoose.model('Seats', new mongoose.Schema({ + + + const seatsSchema = new mongoose.Schema({ org: String, team: String, assigning_team_id: Number, @@ -249,6 +247,14 @@ class Database { mongoose.model('Seats', seatsSchema); + // Create models 📦 + mongoose.model('Team', teamSchema); + mongoose.model('Member', memberSchema); + mongoose.model('TeamMember', teamMemberSchema); + mongoose.model('Counter', counterSchema); // Ensure Counter model is registered here + console.log('Created Counter model'); + mongoose.model('Seats', seatsSchema); + mongoose.model('Survey', new mongoose.Schema({ id: Number, userId: String,