Next.js Discord

Discord Forum

How to add tags on db call on server component to revalidate using tags ?

Answered
Tan posted this in #help-forum
Open in Discord
TanOP
I wanted to revalidate db fetch using tags. It is being done with path but I couldn't figure out how can I revalidate using tags since I am not using fetch.

Here is my code snippet :
const page = async () => {
  await connect();
  const posts = await Post.find();
  return (
    <div>
      <div className="container mx-auto py-8">
        <h1 className="text-2xl font-semibold text-center mb-4">
          Create a New Post
        </h1>
        <Form />
      </div>
      <div className="max-w-4xl mx-auto">
        <h1 className="text-3xl"></h1>
        {posts.map((post) => (
          <li>{post.title}</li>
        ))}
      </div>
    </div>
  );
};
Answered by fuma
Unfortunately, for now, you can't cache or revalidate database calls. Instead, you can revalidate the whole page with revalidatePath.
Next.js also provides a unstable_cache, but it is discouraged to use in production and might not work as expected.
View full answer

2 Replies