Skip to content

Commit 5f795a1

Browse files
committed
minor refactoring
1 parent 2587bad commit 5f795a1

7 files changed

Lines changed: 771 additions & 1 deletion

File tree

.dockerignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# ---------------------------------------------------------------------------------*
2+
# This will prevent your local modules and debug logs from being copied onto your
3+
# Docker image and possibly overwriting modules installed within your image.
4+
# ---------------------------------------------------------------------------------*
5+
node_modules
6+
npm-debug.log
7+
# ignore .git and .cache folders
8+
.git
9+
.cache
10+
# ignore all markdown files (md) beside all README*.md other than README-secret.md
11+
*.md
12+
!README*.md
13+
# github related files
14+
.github/
15+
# nodejs releated files
16+
node_modules
17+
.nyc_output
18+
.talismanrc
19+
coverage
20+
test-results.xml
21+
#reports
22+
reports*
23+
zap*
24+
dependency*
25+
jenkins*
26+
trivy-image*
27+
terraform
28+
db-data

.gitignore

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,29 @@ test-results.xml
77

88
# Environment variables (DO NOT COMMIT)
99
.env
10-
.env.local
10+
.env.local
11+
12+
# Terraform state files
13+
*.tfstate
14+
*.tfstate.*
15+
*.tfvars
16+
!terraform.tfvars.example
17+
18+
# Terraform directories
19+
.terraform/
20+
.terraform.lock.hcl
21+
22+
# Crash log files
23+
crash.log
24+
crash.*.log
25+
26+
# Override files
27+
override.tf
28+
override.tf.json
29+
*_override.tf
30+
*_override.tf.json
31+
32+
# CLI configuration files
33+
.terraformrc
34+
terraform.rc
35+
copilot-instructions*

db-data/MONGODB_SETUP.md

Lines changed: 278 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,278 @@
1+
# MongoDB Planet Data Import Guide
2+
3+
## Overview
4+
This guide will help you populate your MongoDB Atlas database with planet data for the Solar System application.
5+
6+
## Data Structure
7+
8+
Each planet document contains:
9+
- **id** (Number): Planet ID from 1-8
10+
- **name** (String): Planet name (Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune)
11+
- **image** (String): URL to planet image
12+
- **velocity** (String): Orbital velocity
13+
- **distance** (String): Distance from the Sun
14+
- **description** (String): Detailed information about the planet
15+
16+
## Method 1: Using Node.js Import Script (Recommended)
17+
18+
### Step 1: Set Environment Variables
19+
20+
```bash
21+
export MONGO_URI="your-mongodb-atlas-uri"
22+
export MONGO_USERNAME="your-username"
23+
export MONGO_PASSWORD="your-password"
24+
```
25+
26+
### Step 2: Run Import Script
27+
28+
```bash
29+
node import-planets.js
30+
```
31+
32+
Expected output:
33+
```
34+
Connecting to MongoDB...
35+
✅ Connected to MongoDB successfully!
36+
37+
Clearing existing planet data...
38+
✅ Existing data cleared
39+
40+
Importing planet data...
41+
✅ Successfully imported 8 planets!
42+
43+
Imported planets:
44+
- ID: 1, Name: Mercury
45+
- ID: 2, Name: Venus
46+
- ID: 3, Name: Earth
47+
- ID: 4, Name: Mars
48+
- ID: 5, Name: Jupiter
49+
- ID: 6, Name: Saturn
50+
- ID: 7, Name: Uranus
51+
- ID: 8, Name: Neptune
52+
53+
Verifying data...
54+
✅ Total planets in database: 8
55+
56+
✅ Database connection closed. Import complete!
57+
```
58+
59+
## Method 2: Using MongoDB Atlas Web Interface
60+
61+
### Step 1: Go to MongoDB Atlas
62+
1. Log in to https://cloud.mongodb.com/
63+
2. Navigate to your cluster
64+
3. Click "Browse Collections"
65+
4. Select database: `solar-system`
66+
5. Select collection: `planets`
67+
68+
### Step 2: Insert Documents
69+
Click "INSERT DOCUMENT" and paste each planet document:
70+
71+
#### Mercury
72+
```json
73+
{
74+
"id": 1,
75+
"name": "Mercury",
76+
"image": "https://gitlab.com/sidd-harth/solar-system/-/raw/main/images/mercury.png",
77+
"velocity": "47 km/s",
78+
"distance": "57.9 million km",
79+
"description": "Mercury is the smallest planet in the Solar System and the closest to the Sun. Its orbit around the Sun takes 87.97 Earth days, the shortest of all the Sun's planets. It is named after the Roman god Mercurius (Mercury), god of commerce, messenger of the gods, and mediator between gods and mortals."
80+
}
81+
```
82+
83+
#### Venus
84+
```json
85+
{
86+
"id": 2,
87+
"name": "Venus",
88+
"image": "https://gitlab.com/sidd-harth/solar-system/-/raw/main/images/venus.png",
89+
"velocity": "35 km/s",
90+
"distance": "108.2 million km",
91+
"description": "Venus is the second planet from the Sun. It is sometimes called Earth's 'sister' or 'twin' planet as it is almost as large and has a similar composition. As an interior planet to Earth, Venus (like Mercury) appears in Earth's sky never far from the Sun, either as morning star or evening star."
92+
}
93+
```
94+
95+
#### Earth
96+
```json
97+
{
98+
"id": 3,
99+
"name": "Earth",
100+
"image": "https://gitlab.com/sidd-harth/solar-system/-/raw/main/images/earth.png",
101+
"velocity": "29 km/s",
102+
"distance": "149.6 million km",
103+
"description": "Earth is the third planet from the Sun and is the largest of the terrestrial planets. The Earth is the only planet in our solar system not to be named after a Greek or Roman deity. The Earth was formed approximately 4.54 billion years ago and is the only known planet to support life. Earth has one Moon, the largest moon of any rocky planet in the Solar System."
104+
}
105+
```
106+
107+
#### Mars
108+
```json
109+
{
110+
"id": 4,
111+
"name": "Mars",
112+
"image": "https://gitlab.com/sidd-harth/solar-system/-/raw/main/images/mars.png",
113+
"velocity": "24 km/s",
114+
"distance": "227.9 million km",
115+
"description": "Mars is the fourth planet from the Sun and the second-smallest planet in the Solar System, being larger than only Mercury. In English, Mars carries the name of the Roman god of war and is often called the 'Red Planet'. The latter refers to the effect of the iron oxide prevalent on Mars's surface, which gives it a reddish appearance distinctive among the astronomical bodies visible to the naked eye."
116+
}
117+
```
118+
119+
#### Jupiter
120+
```json
121+
{
122+
"id": 5,
123+
"name": "Jupiter",
124+
"image": "https://gitlab.com/sidd-harth/solar-system/-/raw/main/images/jupiter.png",
125+
"velocity": "13 km/s",
126+
"distance": "778.5 million km",
127+
"description": "Jupiter is the fifth planet from the Sun and the largest in the Solar System. It is a gas giant with a mass more than two and a half times that of all the other planets in the Solar System combined, but slightly less than one-thousandth the mass of the Sun. Jupiter is the third brightest natural object in the Earth's night sky after the Moon and Venus."
128+
}
129+
```
130+
131+
#### Saturn
132+
```json
133+
{
134+
"id": 6,
135+
"name": "Saturn",
136+
"image": "https://gitlab.com/sidd-harth/solar-system/-/raw/main/images/saturn.png",
137+
"velocity": "9.7 km/s",
138+
"distance": "1.434 billion km",
139+
"description": "Saturn is the sixth planet from the Sun and the second-largest in the Solar System, after Jupiter. It is a gas giant with an average radius of about nine and a half times that of Earth. It has only one-eighth the average density of Earth; however, with its larger volume, Saturn is over 95 times more massive. Saturn's interior is most likely composed of a rocky core, surrounded by a deep layer of metallic hydrogen."
140+
}
141+
```
142+
143+
#### Uranus
144+
```json
145+
{
146+
"id": 7,
147+
"name": "Uranus",
148+
"image": "https://gitlab.com/sidd-harth/solar-system/-/raw/main/images/uranus.png",
149+
"velocity": "6.8 km/s",
150+
"distance": "2.871 billion km",
151+
"description": "Uranus is the seventh planet from the Sun. Its name is a reference to the Greek god of the sky, Uranus (Caelus), who, according to Greek mythology, was the great-grandfather of Ares (Mars), grandfather of Zeus (Jupiter) and father of Cronus (Saturn). It has the third-largest planetary radius and fourth-largest planetary mass in the Solar System."
152+
}
153+
```
154+
155+
#### Neptune
156+
```json
157+
{
158+
"id": 8,
159+
"name": "Neptune",
160+
"image": "https://gitlab.com/sidd-harth/solar-system/-/raw/main/images/neptune.png",
161+
"velocity": "5.4 km/s",
162+
"distance": "4.495 billion km",
163+
"description": "Neptune is the eighth planet from the Sun and the farthest known planet in the Solar System. It is the fourth-largest planet in the Solar System by diameter, the third-most-massive planet, and the densest giant planet. It is 17 times the mass of Earth, and slightly more massive than its near-twin Uranus. Neptune is denser and physically smaller than Uranus because its greater mass causes more gravitational compression of its atmosphere."
164+
}
165+
```
166+
167+
## Method 3: Using mongoimport Command Line
168+
169+
### Step 1: Install MongoDB Tools
170+
```bash
171+
# Ubuntu/Debian
172+
sudo apt-get install mongodb-database-tools
173+
174+
# macOS
175+
brew install mongodb-database-tools
176+
```
177+
178+
### Step 2: Import JSON File
179+
```bash
180+
mongoimport --uri "your-mongodb-atlas-uri" \
181+
--username "your-username" \
182+
--password "your-password" \
183+
--db solar-system \
184+
--collection planets \
185+
--file planets-data.json \
186+
--jsonArray
187+
```
188+
189+
## Verification
190+
191+
After importing, verify the data:
192+
193+
### Using Node.js
194+
```bash
195+
# Run the application
196+
export MONGO_URI="your-uri"
197+
export MONGO_USERNAME="your-username"
198+
export MONGO_PASSWORD="your-password"
199+
npm start
200+
201+
# Test endpoint
202+
curl -X POST http://localhost:3000/planet \
203+
-H "Content-Type: application/json" \
204+
-d '{"id": 3}'
205+
```
206+
207+
Expected response for Earth (id: 3):
208+
```json
209+
{
210+
"_id": "...",
211+
"id": 3,
212+
"name": "Earth",
213+
"image": "https://gitlab.com/sidd-harth/solar-system/-/raw/main/images/earth.png",
214+
"velocity": "29 km/s",
215+
"distance": "149.6 million km",
216+
"description": "Earth is the third planet from the Sun and is the largest of the terrestrial planets..."
217+
}
218+
```
219+
220+
### Using MongoDB Atlas
221+
1. Go to Collections → solar-system → planets
222+
2. You should see 8 documents (planets)
223+
3. Each document should have: id, name, image, velocity, distance, description
224+
225+
## Troubleshooting
226+
227+
### Connection Error
228+
**Problem**: Cannot connect to MongoDB
229+
**Solution**:
230+
- Verify your connection string is correct
231+
- Check Network Access in MongoDB Atlas (add 0.0.0.0/0 for testing)
232+
- Verify username/password are correct
233+
234+
### Import Script Fails
235+
**Problem**: `node import-planets.js` fails
236+
**Solution**:
237+
- Make sure `planets-data.json` exists in the same directory
238+
- Verify environment variables are set correctly
239+
- Check if mongoose is installed: `npm install`
240+
241+
### Data Not Showing
242+
**Problem**: Application runs but no planet data returned
243+
**Solution**:
244+
- Verify database name is exactly `solar-system`
245+
- Verify collection name is exactly `planets`
246+
- Check if data was actually imported (use MongoDB Atlas interface)
247+
- Verify the `id` field is a Number, not a String
248+
249+
## Testing with Unit Tests
250+
251+
After importing data, run the unit tests:
252+
```bash
253+
npm test
254+
```
255+
256+
All 11 tests should pass if data is imported correctly:
257+
- ✅ it should fetch a planet named Mercury
258+
- ✅ it should fetch a planet named Venus
259+
- ✅ it should fetch a planet named Earth
260+
- ✅ it should fetch a planet named Mars
261+
- ✅ it should fetch a planet named Jupiter
262+
- ✅ it should fetch a planet named Saturn
263+
- ✅ it should fetch a planet named Uranus
264+
- ✅ it should fetch a planet named Neptune
265+
- ✅ it should fetch OS details
266+
- ✅ it checks Liveness endpoint
267+
- ✅ it checks Readiness endpoint
268+
269+
## Next Steps
270+
271+
1. ✅ Import planet data using one of the methods above
272+
2. ✅ Verify data in MongoDB Atlas
273+
3. ✅ Test locally with `npm start`
274+
4. ✅ Run unit tests with `npm test`
275+
5. ✅ Add MongoDB credentials to GitHub Secrets
276+
6. ✅ Push code to trigger DevSecOps pipeline
277+
278+
Good luck! 🚀

0 commit comments

Comments
 (0)