Unverified Commit 6079dc24 authored by Arsalan Khattak's avatar Arsalan Khattak Committed by GitHub

Fetch Data on Runtime (with-MongoDB-mongoose example) (#14674)

Change Data Fetching Method in Example with-mongodb-mongoose
Fetch Data on Runtime (getServerSideProps) rather than Build Time (getStaticProps)
parent ac5b2acd
...@@ -63,16 +63,7 @@ const PetPage = ({ pet }) => { ...@@ -63,16 +63,7 @@ const PetPage = ({ pet }) => {
) )
} }
export async function getStaticPaths() { export async function getServerSideProps({ params }) {
await dbConnect()
const result = await Pet.find({})
const paths = result.map((doc) => ({ params: { id: doc._id.toString() } }))
return { paths, fallback: false }
}
export async function getStaticProps({ params }) {
await dbConnect() await dbConnect()
const pet = await Pet.findById(params.id).lean() const pet = await Pet.findById(params.id).lean()
......
...@@ -48,7 +48,7 @@ const Index = ({ pets }) => ( ...@@ -48,7 +48,7 @@ const Index = ({ pets }) => (
) )
/* Retrieves pet(s) data from mongodb database */ /* Retrieves pet(s) data from mongodb database */
export async function getStaticProps() { export async function getServerSideProps() {
await dbConnect() await dbConnect()
/* find all the data in our database */ /* find all the data in our database */
......
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