Adding New Properties to an Existing MongoDB Entity

Tuesday, June 3, 2025 –  Last week, I was assigned a new backend-related task. The objective was to enhance an existing API by adding a few new properties to one of the current entities.

I started by updating the existing database diagram using Visio to reflect the new properties. Since the system uses MongoDB, there was no need to handle database migrations, MongoDB’s schema-less nature made the update process more straightforward.

After confirming the updated design with Mr. Peter, I proceeded to add the new properties directly into the existing entity class. These properties didn’t require any new relationships, so I was able to jump straight into modifying the update command. Note that the create command didn’t need any changes, as the new fields weren’t involved in initial data creation.

Once the update command logic was in place, I wrote a new unit test to ensure the changes worked as expected. After verifying that the backend logic was functional, I moved on to the UI. The UI changes were relatively simple, involving just an additional checkbox. I created the wrapper component and mapped the new property accordingly.

However, during testing, the update functionality didn’t behave as expected. Although everything seemed correctly configured, the data wasn’t updating. This led me to re-run the unit tests. One of them failed, while another passed but revealed that a property expected to be non-nullable was receiving zero or empty data instead.

After some debugging and with help from Mr. Peter, we discovered the issue: a DTO (Data Transfer Object) required the same property name as the corresponding entity to ensure correct mapping. Once this was corrected, everything functioned as expected. With the update logic complete, I’ll now move on to the Get List API Query, which I plan to work on next week.