From fa94d1f41b052e543e9d5fe1bbebfe4888bdd5da Mon Sep 17 00:00:00 2001 From: harimkims Date: Sun, 31 Oct 2021 03:26:10 +0900 Subject: [PATCH 1/3] Remove deprecated function --- examples/with-mongodb/lib/mongodb.js | 5 +---- examples/with-mongodb/package.json | 2 +- examples/with-mongodb/pages/index.js | 27 +++++++++++++++------------ package.json | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/examples/with-mongodb/lib/mongodb.js b/examples/with-mongodb/lib/mongodb.js index 2990cffd2cac4..0eef49bf49936 100644 --- a/examples/with-mongodb/lib/mongodb.js +++ b/examples/with-mongodb/lib/mongodb.js @@ -1,10 +1,7 @@ import { MongoClient } from 'mongodb' const uri = process.env.MONGODB_URI -const options = { - useUnifiedTopology: true, - useNewUrlParser: true, -} +const options = {} let client let clientPromise diff --git a/examples/with-mongodb/package.json b/examples/with-mongodb/package.json index fd7f9f0ba2603..f03fe2598d01f 100644 --- a/examples/with-mongodb/package.json +++ b/examples/with-mongodb/package.json @@ -6,7 +6,7 @@ "start": "next start" }, "dependencies": { - "mongodb": "^3.5.9", + "mongodb": "^4.1.3", "next": "latest", "react": "^17.0.2", "react-dom": "^17.0.2" diff --git a/examples/with-mongodb/pages/index.js b/examples/with-mongodb/pages/index.js index 9628afb6523c7..6f5c6a2dc19c5 100644 --- a/examples/with-mongodb/pages/index.js +++ b/examples/with-mongodb/pages/index.js @@ -223,17 +223,20 @@ export default function Home({ isConnected }) { } export async function getServerSideProps(context) { - const client = await clientPromise - - // client.db() will be the default database passed in the MONGODB_URI - // You can change the database by calling the client.db() function and specifying a database like: - // const db = client.db("myDatabase"); - // Then you can execute queries against your database like so: - // db.find({}) or any of the MongoDB Node Driver commands - - const isConnected = await client.isConnected() - - return { - props: { isConnected }, + try { + // client.db() will be the default database passed in the MONGODB_URI + // You can change the database by calling the client.db() function and specifying a database like: + // const db = client.db("myDatabase"); + // Then you can execute queries against your database like so: + // db.find({}) or any of the MongoDB Node Driver commands + const client = await clientPromise + return { + props: { isConnected: true }, + } + } catch (e) { + console.error(e) + return { + props: { isConnected: false }, + } } } diff --git a/package.json b/package.json index 8c2cee2dc9c3b..c31121368c10b 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "dev": "lerna run dev --stream --parallel", "dev2": "while true; do yarn --check-files && yarn dev; done", "test-types": "yarn tsc", - "test": "yarn jest", + "test": "yarn jestasd", "test-unit": "yarn jest test/unit/", "testonly": "yarn jest --runInBand", "testheadless": "cross-env HEADLESS=true yarn testonly", From 8c3abc7c9c711591230bf0e80807db1622a4a8a0 Mon Sep 17 00:00:00 2001 From: harimkims Date: Sun, 31 Oct 2021 03:36:54 +0900 Subject: [PATCH 2/3] Remove useless change --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c31121368c10b..8c2cee2dc9c3b 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "dev": "lerna run dev --stream --parallel", "dev2": "while true; do yarn --check-files && yarn dev; done", "test-types": "yarn tsc", - "test": "yarn jestasd", + "test": "yarn jest", "test-unit": "yarn jest test/unit/", "testonly": "yarn jest --runInBand", "testheadless": "cross-env HEADLESS=true yarn testonly", From 16e0e0d5d3f7832d70158b624b6602ffd1cd560a Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Tue, 30 Nov 2021 15:37:58 -0600 Subject: [PATCH 3/3] lint-fix --- examples/with-mongodb/pages/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/with-mongodb/pages/index.js b/examples/with-mongodb/pages/index.js index 6f5c6a2dc19c5..a57dfe93bfb97 100644 --- a/examples/with-mongodb/pages/index.js +++ b/examples/with-mongodb/pages/index.js @@ -229,7 +229,7 @@ export async function getServerSideProps(context) { // const db = client.db("myDatabase"); // Then you can execute queries against your database like so: // db.find({}) or any of the MongoDB Node Driver commands - const client = await clientPromise + await clientPromise return { props: { isConnected: true }, }