I'm trying to connect to my sample mongoDB collection using getInitialProps inside my _app.js but I'm having this issue of Module not found: Can't resolve 'dns'
_app.js
import { connectToDatabase } from '../middlewares/mongodb';
function MyApp({ Component, pageProps, prop }) {
return (
<Layout>
<Component {...pageProps} />
</Layout>
);
}
MyApp.getInitialProps = async (appContext) => {
const { db } = await connectToDatabase();
const data = await db
.collection('listingsAndReviews')
.find({})
.limit(10)
.toArray();
const prop = JSON.parse(JSON.stringify(data));
return { ...prop };
};