import Head from 'next/head' import clientPromise from '../lib/mongodb' export default function Home({ isConnected }) { return (
Create Next App

Welcome to Next.js with MongoDB!

{isConnected ? (

You are connected to MongoDB

) : (

You are NOT connected to MongoDB. Check the README.md{' '} for instructions.

)}

Get started by editing pages/index.js

Documentation →

Find in-depth information about Next.js features and API.

Learn →

Learn about Next.js in an interactive course with quizzes!

Examples →

Discover and deploy boilerplate example Next.js projects.

Deploy →

Instantly deploy your Next.js site to a public URL with Vercel.

) } export async function getServerSideProps(context) { 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 }, } } }