Me, myself and my lack of knowledge

When I was like Jon Snow and knew absolutely nothing (especially from databases) I thought that all databases are treated equal. Just pick one and use that. When I knew a tad more than nothing I thought that why would anyone ever need a relational database because MongoDB can do everything just fine. Even when I started a course on relational databases in school I still had the same thought.

During that course I started to realize why one would need a relational database but at the same time I was still sure that I would not need one. Like ever. And again I was wrong. A friend was wondering why I didn’t have the possibility for people to comment on my blog posts. I didn’t even think that would be necessary. I mean it’s quite random that anyone would ever stumble on my blog and even if someone did why would he/she comment on my ramblings?

But since I had not yet made it possible for myself to even edit my posts (don’t ask why..) I decided to enable commenting as well. Everything went quite smoothly at first. Did the routing and front end component for comments. Then I stopped to think that how am I supposed to let MongoDB know that a blog post and comments are related to each other. It is not a relational database and here I finally realized how ignorant I had been. Now I actually understand why relational databases are needed in the real world.

Since I was not that confident (yet) with my database building skills I decided to stick with MongoDB for better or worse. I made a collection for comments and when a user posts a comment it has a property of blogpostID which is used for getting the right comments for each post. In the end it was not that big of a problem. The bigger problem was when I wanted to implement comment counter for each post. I couldn’t figure out a way to update two different collections (it’s probably quite simple in the end) at the same time.

Eventually I found a good documentation by MongoDB for Two Phase Commits but at this point I had decided to give up. But I gave up only because I planned to build a relational database for my blog as a school project which is required later on. I thought that this could be a nice one because I have real world use for it and it’s always more fun to build things that one actually has use for.


Leave a Reply

Your email address will not be published. Required fields are marked *