Setting up MongoDB
1. Sign Up or Log In¶
- Sign Up:
- Go to MongoDB Atlas.
- Click on "Start Free" to create a new account.
-
Provide your email and create a password or sign up using Google, GitHub, or Microsoft.
-
Log In:
- If you already have an account, click "Log In" and enter your credentials.
2. Create a New Project¶
- Step:
- After logging in, click on "Projects" in the left sidebar.
-
Click the "New Project" button.
-
Details:
- Enter a project name and optionally a description.
- Click "Next" to proceed.
3. Build a New Cluster¶
- Step:
-
In the new project dashboard, click "Build a Cluster."
-
Details:
- Cloud Provider: Choose a cloud provider (AWS, Google Cloud, or Azure).
- Region: Select a geographic region for your cluster.
- Cluster Tier: Choose the free tier (M0 Sandbox) or select a different tier based on your needs.
-
Additional Settings: You can configure options like cluster name and backup settings.
-
Action:
- Click "Create Cluster" to initiate the process.
4. Configure Cluster Access¶
- Step:
-
Add a Database User:
- Go to the "Database Access" tab.
- Click "Add New Database User."
- Create a username and password.
- Set the user’s database access permissions (read and write to any database is common for development).
- Click "Add User."
-
Set Network Access:
- Go to the "Network Access" tab.
- Click "Add IP Address."
- Add your IP address or use the "Allow Access from Anywhere" option (for development, use 0.0.0.0/0).
- Click "Confirm."
5. Get Connection String¶
- Step:
-
Connect to Your Cluster:
- Go to the "Clusters" tab.
- Click the "Connect" button next to your cluster.
- Select "Connect Your Application."
- Copy the connection string provided.
-
Details:
- Replace
<username>
,<password>
, and<dbname>
in the connection string with your MongoDB Atlas username, password, and desired database name.
6. Connect Using a MongoDB Client¶
- Step:
- Using MongoDB Compass:
- Download and install MongoDB Compass.
- Open Compass and paste the connection string.
- Click "Connect."
7. Create a Database and Collection¶
- Step:
-
Once connected, you can create a new database and collection within MongoDB Atlas.
-
Details:
-
Create a Database:
- Click on "Databases" tab in MongoDB Compass.
- Click "Create Database."
- Enter the database name and initial collection name.
- Click "Create Database."
-
Create Collections:
- Within your database, you can add new collections and manage documents.