-1

This is an issue I am struggeling for a while, once you reference an ObjectId within a document in MongoDB and later serialise it as JSON, it will throw an error

Error: Error serializing `.kurs` returned from `getServerSideProps` in "/course".
Reason: `object` ("[object Uint8Array]") cannot be serialized as JSON. Please only return JSON serializable data types.

This is due to that ObjectId is not autoconvertible to string, is there any fix for that or a good approach?

marius
  • 1,118
  • 1
  • 18
  • 38
  • 1
    Could you provide is with more code? it's hard to visualize how it's currently being implemented in your code without a reference. https://stackoverflow.com/help/minimal-reproducible-example – Dylan L. Apr 12 '22 at 22:32

1 Answers1

0

Maybe you can call the toString() method on these properties to get the correct string values.

Or write something with:

JSON.stringify(dataObject)

EDITED: something like this work in my code

export async function getStaticData() {
    const data = await getAllData();
    const allData = JSON.stringify(data)

    return {
        props: {
             allData
        }
   };
}