0

I am unsure why with mongodb and Nextjs I am having to re do JSON.parse on data that I have fetching from MongoDB.

function PodcastUpload({ data }) {

  const [value, setValue] = useState('');
  var eD = JSON.parse(data);
  eD = eD[0]

the data is from


export async function getServerSideProps(ctx) {
   
      const token = await getSession(ctx)
      const data =  await getLatestEpisodeData(token,ctx.params.podcastName)
      
      return { props: { data } }
  
}
    

which gets the data from

export async function getLatestEpisodeData(token, showname) {
   
 
    if (token) {
      // Signed in
      const uuid = token.uuid;
  
  
     try {
          const client = await clientPromise;
          const db = client.db("DRN1");
         
          const shows = await db
              .collection("episode")
              //.findOne({show_b: showname})
              //.toArray()
              .find({'show_b': showname})
              .sort({_id:-1})
              .limit(1)
              .toArray();
  
              return(JSON.stringify(shows));
          
         
      } catch (e) {
          console.error(e);
      }
  
    }
}

I have tried to remove the JSON.stringify however that brings up a SerializableError: Error serializing .datareturned fromgetServerSideProps in "/staff/podcasts/[podcastName]/upload".

RussellHarrower
  • 6,470
  • 21
  • 102
  • 204
  • Does this answer your question: [Error: How to serialize data from getStaticProps : Next.js](https://stackoverflow.com/questions/66106776/error-how-to-serialize-data-from-getstaticprops-next-js)? – juliomalves Oct 14 '22 at 21:16

1 Answers1

0

Have you tried logging data in your getServerSideProps ? I usually get this error when one of my props is undefined

Max
  • 71
  • 3