Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix with-mongo example by removing deprecated function #30675

Merged
merged 6 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 },
}
}
}