Skip to content

Commit 438ee65

Browse files
authored
Express: Update mongoose to latest (#344)
1 parent 5f2b673 commit 438ee65

5 files changed

Lines changed: 108 additions & 25 deletions

File tree

bin/www

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ app.set("port", port);
1919
* Set up mongoose connection
2020
*/
2121
const mongoose = require("mongoose");
22-
mongoose.set("strictQuery", false);
2322
const dev_db_url =
2423
"mongodb+srv://cooluser:coolpassword@cluster0.cojoign.mongodb.net/local_library?retryWrites=true&w=majority&appName=Cluster0";
2524
const mongoDB = process.env.MONGODB_URI || dev_db_url;
@@ -33,6 +32,15 @@ try {
3332

3433
async function connectMongoose() {
3534
await mongoose.connect(mongoDB);
35+
36+
// Add connection error handlers
37+
mongoose.connection.on('error', err => {
38+
console.error('MongoDB connection error:', err);
39+
});
40+
41+
mongoose.connection.on('disconnected', () => {
42+
console.warn('MongoDB disconnected');
43+
});
3644
}
3745

3846
/**

package-lock.json

Lines changed: 97 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"helmet": "^8.1.0",
2222
"http-errors": "^2.0.0",
2323
"luxon": "^3.6.1",
24-
"mongoose": "^8.16.2",
24+
"mongoose": "^9.2.1",
2525
"morgan": "^1.10.0",
2626
"pug": "^3.0.3"
2727
},

populatedb.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ const books = [];
1818
const bookinstances = [];
1919

2020
const mongoose = require("mongoose");
21-
mongoose.set("strictQuery", false);
2221

2322
const mongoDB = userArgs[0];
2423

@@ -33,7 +32,7 @@ async function main() {
3332
await createBooks();
3433
await createBookInstances();
3534
console.log("Debug: Closing mongoose");
36-
mongoose.connection.close();
35+
await mongoose.connection.close();
3736
}
3837

3938
// We pass the index to the ...Create functions so that, for example,

test/utils/test_db.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ let mongoServer;
88
async function connect() {
99
mongoServer = await MongoMemoryServer.create();
1010
const uri = mongoServer.getUri();
11-
mongoose.set("strictQuery", false);
1211
await mongoose.connect(uri);
1312
}
1413

0 commit comments

Comments
 (0)