I'm trying to load data from mongodb into nextjs but keep recieving this error. The data has been entered the database by Python pymongo.
SerializableError: Error serializing .jobs[0] returned from getServerSideProps in "/". Reason: undefined cannot be serialized as JSON. Please use null or omit this value.
.jobs[0]
getServerSideProps
undefined
null
Here is my function:
export async function getServerSideProps(context) { const { db } = await connectToDatabase(); const data = await db .collection("alljobs") .find() .sort({ _id: 1 }) .limit(40) .toArray(); const jobs = data.map((job) => { const company = JSON.parse(JSON.stringify(job.company)); const impact = JSON.parse(JSON.stringify(job.impact)); const date = JSON.parse(JSON.stringify(job.date)); const role = JSON.parse(JSON.stringify(job.role)); const location = JSON.parse(JSON.stringify(job.location)); const category = JSON.parse(JSON.stringify(job.category)); const link = JSON.parse(JSON.stringify(job.link)); return; { company: company; impact: impact; date: date; role: role; location: location; category: category; link: link; } }); return { props: { jobs }, }; }
2.1m questions
2.1m answers
60 comments
56.9k users