I hope my solution solves the issue you faced.
By default, process.env variables in Next.js are only available in the client and server-side code executed by Next.js. However, in your backend server, you need to ensure the environment variables are properly loaded.
Please try to use a .env.local file in the root of your project to define your environment variables.
In Next.js, environment variables used in the client-side code must start with NEXT_PUBLIC_. However, this does not apply to server-side code, including your database connection.
Ensure you are not adding the NEXT_PUBLIC_ prefix to MONGODB_URI, as it is meant for server-side usage.
Thanks in advance.