When using MongoDB with a strong OOP language like Java, it’s a no brainer to want to hack the MongoDB Java Driver to serialize data to different sub-classes of model classes given different shapes of data, because MongoDB doesn’t have a strict schema restriction for a collection, which makes it a perfect match to store data models with polymorphism or inheritance into the same collection. This post will explore into how can we adapt polymorphism to MongoDB Java Driver.

Example

The post will use invoice line items as an example to demonstrate how to achieve polymorphism in MongoDB.

For line…


I’ve been learning docker intermittently for a while. Every time I learned, I had to pick up the command again. This might be the case for most of y’all. Besides, I was kind shocked that there are 3 different ways (I’m referring to ENTRYPOINT, RUN, CMD here) to run a command in docker, which later I learned it’s 6 different ways to be exact (exec mode and shell mode). so I am planning a series about learning Docker by demand. The series will be designed to cater to some specific use cases (e.g.: hosting a web server, a proxy client…


TL;DR: When you are having questions like this. It’s very likely that you are not following Dependency Inversion Principle closely. And my StackOverflow answer is shorter too :

We all know that Stream is good. It removes the overhead of reading files by not loading all the file content to our memory. But what if you have to mock one of your stream one point in your life? I had to when I was working with some legacy code in our code base. And I needed to add unit test to a place where I need to mock a FileInputStream…


Rust community has elaborated the concept of reference, ownership and lifetime more than enough. Even after reading tons of resources, such as the ownership, borrowing, lifetime trilogy on their book of 1.8.0 and Understanding Ownership on their book of current version. I still had a hard time to make my code compilable. Especially, when you have to deal with other concepts in Rust such as smart pointers. That was the pain I went through when I was trying to just implement something as simple as tree equality. Even if I was telling me 3000 times of the In this article…

llllzllll

sharing whatever i learned in a hard way

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store