Skip to content

Commit

Permalink
Fix with-mongo example by removing deprecated function (#30675)
Browse files Browse the repository at this point in the history
* Remove deprecated function

* Remove useless change

* lint-fix

Co-authored-by: JJ Kasper <jj@jjsweb.site>
  • Loading branch information
iicdii and ijjk committed Nov 30, 2021
1 parent 2bd296d commit b290a3d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
5 changes: 1 addition & 4 deletions examples/with-mongodb/lib/mongodb.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/with-mongodb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
27 changes: 15 additions & 12 deletions examples/with-mongodb/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
await clientPromise
return {
props: { isConnected: true },
}
} catch (e) {
console.error(e)
return {
props: { isConnected: false },
}
}
}

0 comments on commit b290a3d

Please sign in to comment.