All Blog Articles

Building Dynamic Websites with Payload NextJS: Setting Up Database and File Storage

Media
Sandro WegmannMay 20, 2025
Set up MongoDB Atlas and Supabase S3 storage for your Payload NextJS projects in minutes.

In today’s digital age, building dynamic websites has become more accessible than ever. One of the powerful tools for creating such websites is Payload NextJS. In this article, we will explore how to set up a MongoDB Atlas database and S3 file storage using Supabase, providing you with the foundational knowledge to build dynamic web applications effectively.

This article provides a comprehensive written step-by-step tutorial based on our video guide available on YouTube at https://www.youtube.com/watch?v=-0CCUkoBDSY. For visual learners or those who prefer following along with video instruction, the YouTube tutorial covers the same content while offering additional context and real-time demonstrations of each step in the process. Both resources will help you successfully set up your database and file storage for Payload NextJS projects.


Table of Contents


Understanding Payload NextJS

Payload NextJS is a robust combination of Payload, a headless CMS, and NextJS, a React-based framework. Together, they offer a seamless way to manage content and build dynamic web applications. This article will guide you through the essential steps to set up your database and file storage, which are crucial for running Payload successfully.


Why Do You Need a Database and File Storage?

Before diving into the setup, it's essential to understand the necessity of having a database and file storage:

  • Database: A database stores all your application data, allowing you to retrieve, update, and manage it efficiently. For our project, we will focus on using MongoDB.
  • File Storage: While local file storage is an option during development, it is not suitable for production environments. Using external file storage ensures that your files are accessible and persistent, especially when deploying your application.


Choosing Your Database: MongoDB vs. Postgres

For this project, we will use MongoDB, specifically MongoDB Atlas, which offers a free tier with 512 MB of storage. This choice is ideal for beginners and small projects. However, it's worth noting that there are other options available:

  • Postgres: Another popular choice for databases, with options like Supabase offering a free tier as well.
  • Vercel: Known for its ease of use but can become costly with increased volume.


Setting Up MongoDB Atlas

Let’s walk through the steps to set up your MongoDB Atlas database:

  1. Create an Account: Sign up for a free account on MongoDB Atlas.
  2. Create a New Project: Navigate to the dashboard and create a project, naming it something relevant like "Website Tutorial V3."
  3. Create a Cluster: As you are on the free plan, you can create a single cluster (M0). Choose AWS as your cloud provider and Frankfurt as your region.
  4. Create a Database User: Set up a user with specific permissions rather than using the admin rights provided by default. This enhances security.
  5. Network Access: Allow access from anywhere to ensure connectivity during development.
mongodb-atlas-database-user-creation-setup.jpg


File Storage Options: S3 Protocol

File storage is another crucial aspect of your application. While you can use local storage during development, it's not reliable for production. Here are some options for file storage:

  • AWS S3: Offers 5 GB for free, but can be complex to set up.
  • Supabase: Provides easy integration with a free tier of 1 GB storage.
  • BunnyCDN: A cost-effective, fast CDN option for media files.


Setting Up Supabase for File Storage

To set up Supabase for your file storage, follow these steps:

  1. Create a Supabase Account: Sign up for a free account.
  2. New Project: Create a new project, specifying the database password and region.
  3. Access Key: Generate an access key to connect your application to Supabase.


Configuring Your Payload Project

Once your database and file storage are set up, it’s time to configure your Payload project. Here’s how:

  1. Create a GitHub Repository: Start by creating a repository and cloning it to your local machine.
  2. Install Payload: Use the command npx create-payload-app@beta to initialize your project.
  3. Choose Project Type: Select a blank project template and specify MongoDB as your database.
  4. Install Storage Plugin: Use pnpm install @payloadcms/storage-s3 to integrate S3 storage with your project.
payload-media-collection-typescript-config-screenshot.jpg


Linking Payload to Supabase S3 Bucket

To link your Payload application to the Supabase S3 bucket, you will need to configure environment variables:

  • S3 Bucket Name: This should match the name you created in Supabase.
  • Access Key ID and Secret: Use the credentials generated in Supabase.
  • Region: Specify the region you selected during Supabase setup.
  • Endpoint: Copy the endpoint provided in Supabase.


Testing Your Setup

After configuring your Payload application, it’s time to test the setup:

  1. Run Development Server: Use npm run dev to start your server.
  2. Create a User: The first time you access the admin panel, you will be prompted to create a user.
  3. Upload Media: Try uploading a media file to ensure everything is functioning correctly.


Troubleshooting Common Issues

As with any setup, you may encounter issues. Here are some common problems and solutions:

  • Bucket Not Found: Ensure you have created the bucket in Supabase.
  • Permission Errors: Double-check your database user permissions and access settings.

Conclusion

In this guide, we walked through the essential steps to set up a MongoDB Atlas database and Supabase S3 file storage for your Payload NextJS application. With the right configuration in place, you can build dynamic websites that are both powerful and efficient. Don't hesitate to explore further and expand your knowledge of Payload NextJS!

Frequently Asked Questions (FAQ)

1. What is Payload NextJS?

Payload NextJS is a combination of Payload, a headless CMS, and NextJS, a React-based framework, allowing developers to create dynamic web applications efficiently.

2. Why should I use MongoDB Atlas?

MongoDB Atlas offers a user-friendly interface, a robust free tier, and additional features like backups and full-text search capabilities, making it an excellent choice for developers.

3. Can I use other databases with Payload?

Yes, while this guide focuses on MongoDB, you can also use other databases like Postgres.

4. What are the benefits of using Supabase for file storage?

Supabase provides a straightforward setup, a free tier, and easy integration with your Payload application, making it an attractive choice for file storage.

5. How do I troubleshoot issues with my setup?

Common issues include bucket not found errors and permission errors. Check your configurations and permissions in both MongoDB Atlas and Supabase.

For further insights and updates, feel free to sign up for our newsletter at AllAboutPayload and explore our video series on dynamic websites with Payload V3 + NextJS on our YouTube channel.