I have created a demo meetup NextJS application and deployed it on Vercel. It works perfectly fine on localhost and on Vercel server as well.
But problem I am facing is that I am not able to fetch the latest record from the MongoDB database.
Let me explain with the example: I have a form which is used to upload/insert the data on MongoDB collection. It is inserting properly on DB and after inserting on the client side (NextJS side) I am redirecting to the home page where I am fetching data from MongoDB using "getStaticProps".
On home page after redirecting I am not able to see latest inserted record. I have to do some changes on the code and need to push it and after doing redeployment it is showing me the latest record. I guess this is not the right way to achieve latest record.
Am I mistaken somewhere?
You are using getStaticProps
, which generates your HTML structure on build. This way, your app is not updating its data whenever they change. It works locally in development
mode because getStaticProps
is "disabled" in this mode (it runs on every request, essentailly becoming getServerSideProps
). Try using getServerSideProps
instead.