Next.js Discord

Discord Forum

Changes in MongoDB not being reflected in production

Unanswered
Cape lion posted this in #help-forum
Open in Discord
Cape lionOP
Hey guys, I moved a NextJS app to production and upon making changes in MongoDB, nothing updates on the website... it's blazingly fast :aww:, but is it with the cost of not updating like that?

Here's my site:
And here in the API you can see the first product it's actually Ashtray dragon I Test and not Ashtray dragon I.

Also, I deployed it on a Digital Ocean droplet and randomly I'll be getting 502 gateway errors... But I'll think about this later.

Can you please please help? Thanks!

10 Replies

Cape lionOP
@Dayo Calling the fetchProducts function

import Product from "@/components/products/product"
import Select from "../dropdown-filter"
import { fetchProducts } from "@/actions/fetchProducts"
import LoadMoreProducts from "@/components/load-more-products"
import ProductsContainer from "./products-container"
export default async function Products() {

    const products = await fetchProducts(1)

    if (products === null) {
        return <></>
    }

    return (
        <div className="border-b border-b-hlinoteka-special">
            <div className="px-2 py-8 sm:p-12 lg:px-24 lg:pt-20 lg:pb-28 flex flex-col max-w-8xl mx-auto">
                <div className="mb-8">
                    <span className="mr-4">Filter produktů</span>
                    {/* <Select /> */}
                </div>
                <ProductsContainer products={products} />
                <div className="mt-16">
                    <LoadMoreProducts />
                </div>
            </div>
        </div>
    )
}


fetchProducts:

"use server"

export async function fetchProducts(page, filter) {
    const apiUrl = `${process.env.URL}/api/products?page=${page}&filter=${filter}`

    try {
        const response = await fetch(apiUrl)
        const data = await response.json()
        return data
    } catch (error) {
        console.log(error)
        return null
    }
}


(sorry for the tabulation)
Cape lionOP
So I found out about this, I'm guessing it's related to revalidating data? https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#revalidating-data

Ideally, it should revalidate only when I update from the admin panel (a second nextjs app). Do you think that's possible?
European sprat
It's possible to do if you revalidateTag("tag") inside a route handler that you hit from the other admin app
but that won't invalidate the router cache on the client side if they've already loaded it
other ways to invalidate are with client components using router.refresh()
Cape lionOP
funny, now I'm also observing that on localhost, even though checking the API routes it's showing the updated information
@Cape lion funny, now I'm also observing that on localhost, even though checking the API routes it's showing the updated information
try opting out of caching and see if it works- export const revalidate = 0;
just put that in your page.tsx
Cape lionOP
this did it for the first products, as I'm fetching them on the server I guess, but I've also edited products that are being loaded the 'infinite scroll' way, (on the client) and those ones still stay the same (also after ctrl+f5)