Unverified Commit b290a3dc authored by Kim, Harim's avatar Kim, Harim Committed by GitHub

Fix with-mongo example by removing deprecated function (#30675)

* Remove deprecated function

* Remove useless change

* lint-fix
Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
parent 2bd296d4
import { MongoClient } from 'mongodb' import { MongoClient } from 'mongodb'
const uri = process.env.MONGODB_URI const uri = process.env.MONGODB_URI
const options = { const options = {}
useUnifiedTopology: true,
useNewUrlParser: true,
}
let client let client
let clientPromise let clientPromise
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
"start": "next start" "start": "next start"
}, },
"dependencies": { "dependencies": {
"mongodb": "^3.5.9", "mongodb": "^4.1.3",
"next": "latest", "next": "latest",
"react": "^17.0.2", "react": "^17.0.2",
"react-dom": "^17.0.2" "react-dom": "^17.0.2"
......
...@@ -223,17 +223,20 @@ export default function Home({ isConnected }) { ...@@ -223,17 +223,20 @@ export default function Home({ isConnected }) {
} }
export async function getServerSideProps(context) { export async function getServerSideProps(context) {
const client = await clientPromise try {
// client.db() will be the default database passed in the MONGODB_URI
// 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:
// You can change the database by calling the client.db() function and specifying a database like: // const db = client.db("myDatabase");
// const db = client.db("myDatabase"); // Then you can execute queries against your database like so:
// Then you can execute queries against your database like so: // db.find({}) or any of the MongoDB Node Driver commands
// db.find({}) or any of the MongoDB Node Driver commands await clientPromise
return {
const isConnected = await client.isConnected() props: { isConnected: true },
}
return { } catch (e) {
props: { isConnected }, console.error(e)
return {
props: { isConnected: false },
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment