
No Comments Yet
Be the first to share your thoughts and start the conversation.
You've built a lot so far, but now it's time to dive deep into the heart of your Stack Overflow clone—the Questions.
Before you start coding, ask yourself: what exactly does a question contain?
What will make it tick? What information will you need to store so it can grow, evolve, and engage your users? 🧐
A question is more than just a string of text. It’s a , in your application. But what exactly defines it? Here’s what you might wonder as you design it:
Does it need a title?
Of course! But what type of title will it be? Should it be a simple string or perhaps something more complex?
What about the content?
This one is tricky. How do you store rich, detailed content? Will it be plain text, or will you support Markdown or HTML?
What metrics will matter?
How will you store the author's identity?
Will each question be linked to a specific user? How do we represent this user’s unique identity in our model?
Question yourself to get your Question Model in shape. Let's get started!
Your mission is to Create a Question Model using Mongoose.
To help you with this task, here are some valuable resources:
Be sure to check these out for a deeper understanding! 📚
First, choose what you want to display for each question on the UI by cross referencing it with provided Figma design. Here are some ideas:
Is this everything? Possibly! But it’s worth double-checking in case something important is missing. 😉
Now that you know what to include, think about how you’ll store each piece of data.
Some fields—like the author and tags—are connected to other entities. Let’s think through them:
Author
Instead of storing all the author’s details here, how about just storing a reference (like their ID) to a separate User model? This way, if the author updates their information (like a name change), it updates everywhere.
Tags
A question can have multiple tags, and tags can connect to multiple questions. How might you represent this many-to-many relationship? Should each question store tags directly, or should it refer to a Tag model?
Answers
Consider whether you want to store answers in the Question model or keep answers in a separate model with a relationship to the Question. (Hint: a separate model makes sense if you expect many answers per question.)
Votes
For votes, you’ll likely want separate fields to keep track of upvotes and downvotes. But consider whether each vote will be linked to specific users (e.g., to prevent duplicate voting).
With each field, ask yourself:
And remember, designing a model is about balancing with the to grow as your app does. Keep iterating, and use the Mongoose docs if you need guidance on setting up relationships!
As they say, “Success is the sum of small efforts, repeated day in and day out.”. Keep trying!
Be the first to share your thoughts and start the conversation.