Best database structure for a pet and human product e-commerce app

I’m making an app that sells stuff for pets and people. It’s got things like pet ice cream, toys, and accessories. For humans, we’ve got ice cream, salads, and other food. I’m not sure how to set up my database.

I thought about two ways to do it:

  1. Make separate collections for pets and people. Each collection would have documents for subcategories, then a collection for products inside those.

  2. Create one big ‘shop’ collection. Inside, have documents for pets and people, with subcollections for each product type.

I want to show products by subcategory, not all mixed up. Also, I need to be able to do pagination easily for each subcategory.

What do you think? Is one of these ways better? Or is there a smarter way to set this up? I’d love to hear your thoughts!

Hey ExploringAtom! Interesting question you’ve got there. Have you thought about using a NoSQL database like MongoDB for this? It could give you a lot of flexibility.

What if you had a single ‘products’ collection, but used tags or arrays to categorize items? Like, each product could have a ‘forPets’ or ‘forHumans’ field, plus tags for subcategories. That way, you’re not locked into a rigid structure, and you can easily add new categories later.

For pagination, you could query based on these fields and use skip/limit methods. It’d be pretty efficient, especially with the right indexes.

Just curious - how many products are you planning to have initially? And do you think you’ll be adding more categories in the future? That could influence the best approach.

Whatever you decide, make sure to test it with a good amount of sample data. Sometimes things that look good on paper can get messy in practice. Good luck with your app!

Hey there! I’d go with option 1 - separate collections for pets n humans. It’s easier to manage and scale. Plus, you can do pagination per subcategory without hassle. Just make sure to add proper indexes for quick queries. Keep it simple, ya know? Good luck with ur app!

I’d recommend a hybrid approach. Create a main ‘products’ collection with documents for each item. Include fields like ‘category’ (pet/human), ‘subcategory’ (toys, food, etc.), and ‘type’ (ice cream, salad, etc.). This structure allows for flexible querying and easy pagination. For efficient retrieval, use compound indexes on category, subcategory, and type. This setup enables you to quickly fetch products for specific categories or subcategories while maintaining a unified product structure.

Consider adding a separate ‘categories’ collection to store metadata about your product hierarchy. This can aid in dynamically generating navigation menus and simplifying future expansions to your product range.