File tree Expand file tree Collapse file tree 3 files changed +17
-17
lines changed Expand file tree Collapse file tree 3 files changed +17
-17
lines changed Original file line number Diff line number Diff line change 1
1
import { MongoClient } from 'mongodb'
2
2
3
3
const uri = process . env . MONGODB_URI
4
- const options = {
5
- useUnifiedTopology : true ,
6
- useNewUrlParser : true ,
7
- }
4
+ const options = { }
8
5
9
6
let client
10
7
let clientPromise
Original file line number Diff line number Diff line change 6
6
"start" : " next start"
7
7
},
8
8
"dependencies" : {
9
- "mongodb" : " ^3.5.9 " ,
9
+ "mongodb" : " ^4.1.3 " ,
10
10
"next" : " latest" ,
11
11
"react" : " ^17.0.2" ,
12
12
"react-dom" : " ^17.0.2"
Original file line number Diff line number Diff line change @@ -223,17 +223,20 @@ export default function Home({ isConnected }) {
223
223
}
224
224
225
225
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
+ }
238
241
}
239
242
}
You can’t perform that action at this time.
0 commit comments