-
Notifications
You must be signed in to change notification settings - Fork 516
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jonas Mongo API #520
base: master
Are you sure you want to change the base?
Jonas Mongo API #520
Conversation
- Set up Express server with MongoDB using Mongoose - Added dotenv for managing environment variables - Seeded Netflix titles from JSON file into MongoDB - Implemented endpoints for fetching all titles, filtering by query parameters (country, release year, rating), and fetching a specific title by ID - Resolved issues with JSON imports and pretty-printing responses - Addressed challenges with properly formatting and querying data - Refactored and debugged code to ensure correct functionality
I’ve encountered an issue where my routes return empty arrays when deployed to Render. Locally, everything works as expected, but the data doesn’t show up in MongoDB Atlas. I’m not sure what the issue is — it could be that the seeding function isn’t running correctly, the connection string is misconfigured, or there’s a problem with how the data is being handled. I’ve checked my JSON file and the seeding logic, and both seem fine, but I can’t figure out why the netflix_titles collection isn’t appearing in Atlas. |
Have you followed this guide? Did you put your reset database variable to true in your env file together with your mongo connection string? If yes, can you console.log what those values are in your server.js file? With this "Locally, everything works as expected, but the data doesn’t show up in MongoDB Atlas." - do you mean that you can access your Atlas database locally? If it's just that you cannot access it on Render, you probably haven't added the correct mongo string on Render (as an env variable). |
You were right, @HIPPIEKICK – it was my environment variable on Atlas that was incorrect. I’ve fixed it, and now Atlas can successfully connect to my database. After 4-5 hours of troubleshooting and making changes to the code to get it working, I noticed that my commits never went through. When I realized the pushes weren’t going through, I tried something called push --force and probably a few other commands, and after that, nothing worked at all. But at least the database and the different routes are now working, so there shouldn’t be any issues with the task’s goal. However, if anything else needs to be changed, I’ll have to redo the project since, no changes are going through ;( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have a look at your deployed link to see if you can get it to work (I can't). Also, I'd probably implement pagination since the dataset is huge (but see that as a stretch goal).
I need to see a working deployment before I can approve, but I saw your comment on having problems pushing. Could you try to clone your repo anew? If you can't get it to work, please let us know of any errors you get and we'll try to help you
try { | ||
const rawData = fs.readFileSync("./data/netflix-titles.json"); | ||
netflixData = JSON.parse(rawData); | ||
console.log(`✅ Loaded ${netflixData.length} titles from JSON file.`); | ||
} catch (error) { | ||
console.error("❌ Error reading or parsing JSON file:", error.message); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this for? 👀
app.get("/netflix_titles/:id", async (req, res) => { | ||
const { id } = req.params; | ||
|
||
try { | ||
const title = await NetflixTitle.findOne({ show_id: Number(id) }); | ||
if (title) { | ||
res.json(title); | ||
} else { | ||
res.status(404).json({ error: "Title not found" }); | ||
} | ||
} catch (error) { | ||
res.status(500).json({ error: "Internal server error" }); | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get this endpoint to work on your deployed version, can you?
const query = {}; | ||
if (country) { | ||
query.country = { $regex: country, $options: "i" }; | ||
} | ||
if (release_year) { | ||
query.release_year = Number(release_year); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice query-building 💯
Thats so strange, it works for me! See the screenshots and can you try the URLs below as well? @HIPPIEKICK Documentation page: https://project-mongo-api-jonas-new.onrender.com/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the descriptive screenshots, I realised that I searched for the Mongo ID and not the show_id 😅 All is good, sorry for the hassle!
https://project-mongo-api-jonas-new.onrender.com/