-
Notifications
You must be signed in to change notification settings - Fork 1
Configure MongoDB for Local Development
The API server requires a MongoDB database to store all its data, including headlines, users, and settings. For local development, running a MongoDB instance directly on your machine using Docker is the recommended approach as it provides a clean, isolated, and consistent environment.
-
Install Docker: If you don't have it already, download and install Docker Desktop for your operating system. This application will manage your Docker images and containers.
-
Pull and Run the MongoDB Image: Open your terminal and run the following command. This single command will automatically:
- Download the latest official
mongoimage from Docker Hub if you don't have it locally. - Create and start a new container from that image.
docker run --name mongodb-local -p 27017:27017 -d mongo:latest
Command Breakdown:
-
--name mongodb-local: Assigns a memorable name to your container for easy management. -
-p 27017:27017: Maps port27017inside the container to port27017on your local machine, allowing the API server to connect. -
-d: Runs the container in "detached" mode, meaning it runs in the background. -
mongo:latest: Specifies the official MongoDB image to use.
- Download the latest official
-
Verify the Container is Running: You can check that your container started successfully by running:
docker ps
You should see
mongodb-localin the list of running containers.
Once your local MongoDB instance is running, you need to tell the API server how to connect to it.
Open your .env file and set the DATABASE_URL variable:
DATABASE_URL="mongodb://localhost:27017/flutter_news_app_db"-
localhost:27017: This is the default host and port for a local MongoDB instance. -
flutter_news_app_db: You can name your database anything you like. The server will create it automatically on first connection if it doesn't exist.
Tip: For a complete overview of all environment variables, see the Configure Environment Variables guide.
For comprehensive details regarding licensing, including trial and commercial options for the entire toolkit, please refer to the toolkit organization page.