Skip to content

Commit b290a3d

Browse files
iicdiiijjk
andauthored
Fix with-mongo example by removing deprecated function (vercel#30675)
* Remove deprecated function * Remove useless change * lint-fix Co-authored-by: JJ Kasper <[email protected]>
1 parent 2bd296d commit b290a3d

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

examples/with-mongodb/lib/mongodb.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import { MongoClient } from 'mongodb'
22

33
const uri = process.env.MONGODB_URI
4-
const options = {
5-
useUnifiedTopology: true,
6-
useNewUrlParser: true,
7-
}
4+
const options = {}
85

96
let client
107
let clientPromise

examples/with-mongodb/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"start": "next start"
77
},
88
"dependencies": {
9-
"mongodb": "^3.5.9",
9+
"mongodb": "^4.1.3",
1010
"next": "latest",
1111
"react": "^17.0.2",
1212
"react-dom": "^17.0.2"

examples/with-mongodb/pages/index.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -223,17 +223,20 @@ export default function Home({ isConnected }) {
223223
}
224224

225225
export async function getServerSideProps(context) {
226-
const client = await clientPromise
227-
228-
// client.db() will be the default database passed in the MONGODB_URI
229-
// You can change the database by calling the client.db() function and specifying a database like:
230-
// const db = client.db("myDatabase");
231-
// Then you can execute queries against your database like so:
232-
// db.find({}) or any of the MongoDB Node Driver commands
233-
234-
const isConnected = await client.isConnected()
235-
236-
return {
237-
props: { isConnected },
226+
try {
227+
// client.db() will be the default database passed in the MONGODB_URI
228+
// You can change the database by calling the client.db() function and specifying a database like:
229+
// const db = client.db("myDatabase");
230+
// Then you can execute queries against your database like so:
231+
// db.find({}) or any of the MongoDB Node Driver commands
232+
await clientPromise
233+
return {
234+
props: { isConnected: true },
235+
}
236+
} catch (e) {
237+
console.error(e)
238+
return {
239+
props: { isConnected: false },
240+
}
238241
}
239242
}

0 commit comments

Comments
 (0)