{"id":2059,"date":"2025-06-16T23:18:36","date_gmt":"2025-06-16T15:18:36","guid":{"rendered":"https:\/\/www.tonghin.com.my\/blog\/?p=2059"},"modified":"2025-06-16T23:18:38","modified_gmt":"2025-06-16T15:18:38","slug":"adding-new-properties-to-an-existing-mongodb-entity","status":"publish","type":"post","link":"https:\/\/www.tonghin.com.my\/blog\/2025\/06\/16\/adding-new-properties-to-an-existing-mongodb-entity\/","title":{"rendered":"Adding New Properties to an Existing MongoDB Entity"},"content":{"rendered":"\n<p>Tuesday, June 3, 2025 \u2013&nbsp; 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.<\/p>\n\n\n\n<p>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&#8217;s schema-less nature made the update process more straightforward.<\/p>\n\n\n\n<p>After confirming the updated design with Mr. Peter, I proceeded to add the new properties directly into the existing entity class. These properties didn\u2019t require any new relationships, so I was able to jump straight into modifying the update command. Note that the create command didn\u2019t need any changes, as the new fields weren\u2019t involved in initial data creation.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>However, during testing, the update functionality didn\u2019t behave as expected. Although everything seemed correctly configured, the data wasn&#8217;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.<\/p>\n\n\n\n<p>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\u2019ll now move on to the Get List API Query, which I plan to work on next week.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Tuesday, June 3, 2025 \u2013&nbsp; 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 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.tonghin.com.my\/blog\/2025\/06\/16\/adding-new-properties-to-an-existing-mongodb-entity\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Adding New Properties to an Existing MongoDB Entity&#8221;<\/span><\/a><\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v15.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Adding New Properties to an Existing MongoDB Entity | Tong Hin&#039;s Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.tonghin.com.my\/blog\/2025\/06\/16\/adding-new-properties-to-an-existing-mongodb-entity\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Adding New Properties to an Existing MongoDB Entity | Tong Hin&#039;s Blog\" \/>\n<meta property=\"og:description\" content=\"Tuesday, June 3, 2025 \u2013&nbsp; 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 &hellip; Continue reading &quot;Adding New Properties to an Existing MongoDB Entity&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.tonghin.com.my\/blog\/2025\/06\/16\/adding-new-properties-to-an-existing-mongodb-entity\/\" \/>\n<meta property=\"og:site_name\" content=\"Tong Hin&#039;s Blog\" \/>\n<meta property=\"article:published_time\" content=\"2025-06-16T15:18:36+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-16T15:18:38+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\">\n\t<meta name=\"twitter:data1\" content=\"2 minutes\">\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/#organization\",\"name\":\"TONG HIN MACHINERY\",\"url\":\"https:\/\/www.tonghin.com.my\/blog\/\",\"sameAs\":[\"https:\/\/www.youtube.com\/channel\/UC60EoxJMNbu8mV0LuEGfrBg\"],\"logo\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/#logo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/www.tonghin.com.my\/blog\/wp-content\/uploads\/2020\/10\/web_logo_180_180.jpg\",\"width\":180,\"height\":180,\"caption\":\"TONG HIN MACHINERY\"},\"image\":{\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/#logo\"}},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/#website\",\"url\":\"https:\/\/www.tonghin.com.my\/blog\/\",\"name\":\"Tong Hin&#039;s Blog\",\"description\":\"Sharing About Technology\",\"publisher\":{\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/www.tonghin.com.my\/blog\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/2025\/06\/16\/adding-new-properties-to-an-existing-mongodb-entity\/#webpage\",\"url\":\"https:\/\/www.tonghin.com.my\/blog\/2025\/06\/16\/adding-new-properties-to-an-existing-mongodb-entity\/\",\"name\":\"Adding New Properties to an Existing MongoDB Entity | Tong Hin&#039;s Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/#website\"},\"datePublished\":\"2025-06-16T15:18:36+00:00\",\"dateModified\":\"2025-06-16T15:18:38+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/2025\/06\/16\/adding-new-properties-to-an-existing-mongodb-entity\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.tonghin.com.my\/blog\/2025\/06\/16\/adding-new-properties-to-an-existing-mongodb-entity\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/2025\/06\/16\/adding-new-properties-to-an-existing-mongodb-entity\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"item\":{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/\",\"url\":\"https:\/\/www.tonghin.com.my\/blog\/\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"position\":2,\"item\":{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/2025\/06\/16\/adding-new-properties-to-an-existing-mongodb-entity\/\",\"url\":\"https:\/\/www.tonghin.com.my\/blog\/2025\/06\/16\/adding-new-properties-to-an-existing-mongodb-entity\/\",\"name\":\"Adding New Properties to an Existing MongoDB Entity\"}}]},{\"@type\":\"Article\",\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/2025\/06\/16\/adding-new-properties-to-an-existing-mongodb-entity\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/2025\/06\/16\/adding-new-properties-to-an-existing-mongodb-entity\/#webpage\"},\"author\":{\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/#\/schema\/person\/81e2366362d8d14b15519395755cee6f\"},\"headline\":\"Adding New Properties to an Existing MongoDB Entity\",\"datePublished\":\"2025-06-16T15:18:36+00:00\",\"dateModified\":\"2025-06-16T15:18:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/2025\/06\/16\/adding-new-properties-to-an-existing-mongodb-entity\/#webpage\"},\"publisher\":{\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/#organization\"},\"articleSection\":\"Experiential\",\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/#\/schema\/person\/81e2366362d8d14b15519395755cee6f\",\"name\":\"nurlailiyuzi\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/5c0d4cc6f7fc881bd56d95bdbb0c4c14?s=96&d=mm&r=g\",\"caption\":\"nurlailiyuzi\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/www.tonghin.com.my\/blog\/wp-json\/wp\/v2\/posts\/2059"}],"collection":[{"href":"https:\/\/www.tonghin.com.my\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tonghin.com.my\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tonghin.com.my\/blog\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tonghin.com.my\/blog\/wp-json\/wp\/v2\/comments?post=2059"}],"version-history":[{"count":2,"href":"https:\/\/www.tonghin.com.my\/blog\/wp-json\/wp\/v2\/posts\/2059\/revisions"}],"predecessor-version":[{"id":2062,"href":"https:\/\/www.tonghin.com.my\/blog\/wp-json\/wp\/v2\/posts\/2059\/revisions\/2062"}],"wp:attachment":[{"href":"https:\/\/www.tonghin.com.my\/blog\/wp-json\/wp\/v2\/media?parent=2059"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tonghin.com.my\/blog\/wp-json\/wp\/v2\/categories?post=2059"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tonghin.com.my\/blog\/wp-json\/wp\/v2\/tags?post=2059"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}