Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
Windows Tipps & SecurityWindows-Update beschädigt wichtige Datenrettungsfunktion(22.09.2026 um 09:04 Uhr)
Sichere ProgrammierungBuilding an Accessible Ecommerce Product Page with WCAG 2.2(22.09.2026 um 03:39 Uhr)
Sichere ProgrammierungGet Your Website Protected in 10 Minutes with SafeLine WAF(22.09.2026 um 08:42 Uhr)
Sichere ProgrammierungIntroduction to SPRINGBOOT(22.09.2026 um 08:42 Uhr)
Windows Tipps & SecurityWindows-Update beschädigt wichtige Datenrettungsfunktion(22.09.2026 um 09:04 Uhr)
Sichere ProgrammierungBuilding an Accessible Ecommerce Product Page with WCAG 2.2(22.09.2026 um 03:39 Uhr)
Sichere ProgrammierungGet Your Website Protected in 10 Minutes with SafeLine WAF(22.09.2026 um 08:42 Uhr)
Sichere ProgrammierungIntroduction to SPRINGBOOT(22.09.2026 um 08:42 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Why I Switched from H2 to MongoDB in My Growing Spring Boot App

When I started building my Expense Tracker application, all I cared about was testing my APIs without the complications of setting up a database. I just needed something lightweight that would let me test my APIs and move fast. That’s w…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

When I started building my Expense Tracker application, all I cared about was testing my APIs without the complications of setting up a database. I just needed something lightweight that would let me test my APIs and move fast.



That’s when I chose H2 Database. It was easy, embedded, and worked right out of the box. But as my application grew and I started incorporating real life scenarios into the app, I began hitting the limitations of H2. That’s when I realized it was time to move to something more scalable and production ready MongoDB.



Honestly, my decision to use MongoDB wasn’t driven by any specific reason. It was simply pre installed on my computer, and I made the laziest move possible I went ahead and used what was already available.



I also had hands on experience testing MongoDB applications when I worked as a tester. Now, using MongoDB to develop my application after switching to development actually made my work more interesting and explorative.



Installing MongoDB Compass



MongoDB Compass is the official GUI for MongoDB that allows you to visualize, explore, and manage your data easily. Here’s how to install it on different operating systems:




  • Windows


  • Download the installer from https://www.mongodb.com/try/download/compass


  • Run the .exe file and follow the installation wizard.


  • Once installed, launch Compass and connect to your local MongoDB instance using:

    mongodb://localhost:27017


  • macOS


  • Download the .dmg file from https://www.mongodb.com/try/download/compass


  • Open the .dmg file and drag MongoDB Compass into your Applications folder.


  • Open Compass and connect using:

    mongodb://localhost:27017


  • Linux


  • Download the .deb package from https://www.mongodb.com/try/download/compass


  • Install it using the terminal:

    sudo dpkg -i mongodb-compass_<version>_amd64.deb

    sudo apt-get install -f


  • Launch Compass from the applications menu or by running:

    mongodb-compass


  • Connect to your MongoDB instance using:

    mongodb://localhost:27017




Configuring MongoDB in Your Spring Boot App



After installing MongoDB and Compass, the next step is to configure your Spring Boot application to use MongoDB instead of H2. Here’s how I did it:




  • Add MongoDB Dependency




<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
<version>4.0.0-M2</version>
</dependency>







  • Update application.properties
    In src/main/resources/application.properties, configure the connection to your local MongoDB instance:




spring.data.mongodb.uri=mongodb://localhost:27017/db_name






Here, db_name is the name of the database MongoDB will create automatically if it doesn’t exist.




  • Update Your Entities



Since MongoDB is document-based, you need to annotate your model classes with @Document instead of JPA’s @Entity.




  • Update Repositories



Switch your repositories to extend MongoRepository instead of JpaRepository:




public interface ExpenseRepository extends MongoRepository<Expense, ObjectId>







  • Test Your App



Run your application and add some expenses. Open MongoDB Compass and you should see your data persisted in the expenses collection. Unlike H2, your data won’t disappear when the app restarts.





Conclusion



Switching from H2 to MongoDB was a simple decision that made a huge difference in my application’s growth. Unlike H2, MongoDB is schemaless, which means I don’t have to define rigid table structures upfront. This flexibility allows me to easily evolve my Expense Tracker app as new features are added, without worrying about database migrations.



Another reason I appreciate MongoDB in my Expense Tracker app is for the Reports API. Reports often need flexible structures sometimes aggregating expenses by day, category, or user, and the fields can vary depending on the type of report. In a traditional table-based database like H2, this would require multiple joins or schema changes. With MongoDB’s document based design, I can store dynamic report data easily, making it much more flexible and scalable for real life reporting needs.



MongoDB’s document based structure also makes it great for handling dynamic data, scalable applications, and real-time analytics. Beyond small projects like mine, MongoDB is widely used in building content management systems, IoT applications, e commerce platforms, and data intensive web services.



Looking back, H2 was perfect for prototyping and testing, but for any real life application with growing data and users, MongoDB is the tool that lets your app scale, adapt, and thrive.

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Why I Switched from H2 to MongoDB in My Growing Spring Boot App

Thematisch verwandte Begriffe: Switched, from, MongoDB, Growing · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-55210 | Joplin is an open source note-taking and to-do application that organise…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick