
Join the Conversation!
Subscribing gives you access to the comments so you can share your ideas, ask questions, and connect with others.
In modern applications, personalization and convenience are key. Users love the ability to save or bookmark content they find helpful, making it easy to revisit and organize. Think about platforms like Stack Overflow or Reddit where users can save posts or questions for future reference. That’s exactly what we’re setting up here.
Your mission is to Create a Collection Model using Mongoose.
To get started, let’s break down what details we’ll need to store for each collection. Think about the essentials:
Each collection will be tied to a specific user and question, so we need a structure that captures this relationship.
As usual, you can use the following resources to help you get started
You’re going to design a Collection Model. Here's how to think about it:
Start by asking, "What do I need to store in the collection?"
You’ll need to store:
You need two relationships in this model:
By using ObjectId, each saved item in a collection is linked to its corresponding user and question document, making data retrieval seamless.
Both author and question should be required. You need a valid user and question to create a collection. This ensures every collection is meaningful and complete.
It’s always a good idea to include timestamps! Mongoose can automatically add createdAt and updatedAt to track when each collection is created or modified.
And that's it!
Finish up the model, and celebrate this addition to your growing toolkit of backend skills!
"Please login to view comments"
Subscribing gives you access to the comments so you can share your ideas, ask questions, and connect with others.