2

I am building an eCommerce website and there is a Category table in my MongoDB database which has a field called path. This field is used to store category hierarchy e.g Boots category will have /women/shoes/boots as the value in the path. I have a similar field in ElasticSearch as well. The path field helps me retrieve all the ads of a category and all of its child categories efficiently using regex. This design is based on Materialized Path Category Hierarchy approach described here: http://learnmongodbthehardway.com/schema/categoryhierarchy/

My question is is it a good approach while designing an eCommerce application to use category names in the path as apposed to category IDs. My concern is category names can change in future which will force me to change the path for all the ads that were created against those categories in ElasticSearch as well as in MongoDB. I am thinking instead of names /women/shoes/boots I use category ids to form the path like /1/13/209 but I am not sure if this could be a problem later on.

The other thing is what do I do when a category is deleted. I want to know what others do. Should I modify all ads or is there a better way to update ads with deleted/modified categories.

Thanks,

1 Answer 1

3

Both names and IDs create a series of difficulties. You already listed a few ones in your question, such as the removal of a parent category. Another major issue is that categories are a completely wrong tool for this task: you should be using tags instead. With a tree, you'll create a lot of confusion for your users and yourself, given that the same product may be identified differently. For instance, where would you put a shoe brush?

In MaintenanceShoesBrushes?

Or WomenShoesMaintenanceBrushes?

Or maybe ShoesMaintenanceBrushes?

Regarding the names versus identifiers, consider:

  • Search engine optimization. If the path is part of the URI, you'd better use names instead of meaningless numbers.

  • Readability. It may not be that fun to work with numeric identifiers that don't mean anything to a developer. “Hey, I think the user 51.927 is complaining again that he can't access the category 671. Can you check please he has the permission 14 granted?”

  • Localization. As soon as the e-commerce site is used in more than one country or in a country with more than one official language, you're out of luck: if you're using names as identifiers, you'll still have a mapping between those identifiers and the text displayed to the users.

2
  • Categories are more of a user-centric term, that could be implemented using tags. Basically a "category" is a pre-canned search based on tags. Browsing products by category is useful to shoppers. At the data level, don't use names as identifiers, but be aware your end users probably will. There needs to be some sort of mapping between names and Ids, with all the complexity that localization brings. Commented Sep 2, 2020 at 16:57
  • @Arseni You are right about the tags. My URLs are already SEO-friendly. My concern is I am using category name based path at the data level not the ID based which I am not comfortable with.
    – Irfan
    Commented Sep 6, 2020 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.