Title: Next.js website hosted on Netlify not displaying updated data from MongoDB API
I have fixed the problem by including the revalidation inside my routes.
import db from "@/utils/dbConnect";
export async function GET() {
// Setting up the full connection string
const collectionName = "projects";
const collection = db.collection(collectionName);
// Finding all documents in the collection
const projects = await collection.find({}).toArray();
// Returning the skills
return new Response(JSON.stringify(projects), {
headers: { "content-type": "application/json" },
});
}
// revalidate every 10 seconds
export const revalidate = 10;
Hello everyone,
I am facing an issue with my Next.js website hosted on Netlify. Locally, everything is working perfectly fine. However, after deploying the website on Netlify using the Next.js runtime, the displayed data from my MongoDB API is always outdated. It takes a long time for the website to reflect the updated data from the database.
EDIT: I tried running “npm run build && npm run start” and I had the same problem as the deployed site, so this issues only happens on the build.
To provide assistance, please refer to the following details:
- Netlify site name: https://aymvn.netlify.app/
- Custom domain: https://aymvn.tech
- Github repository: GitHub - itzAymvn/aymvn.tech: The portfolio showcasing some of my projects and my skills
- Build log and build settings screenshot:
- Build log: https://logpaste.com/yzhJNKh3
- Build settings:
Furthermore, here is an overview of my website’s setup:
- Technology stack: Next.js 13, MongoDB
- The website fetches data from a MongoDB API and displays it using the fetch function.
- Locally, the data updates properly when changes occur in the database by simply refreshing the page.
I would greatly appreciate any assistance in resolving this issue and ensuring that the deployed website on Netlify reflects the most up-to-date data from the MongoDB API in a timely manner.
Thank you in advance for your help!