liveBook · Manning

Panache MongoDB

As explained in Quarkus in Action

quarkus-mongodb-panache is a Quarkus extension that integrates Panache with MongoDB persistence.

Panache MongoDB integrates MongoDB persistence into a Quarkus service through the quarkus-mongodb-panache extension. The implementation follows a short path: install the extension, configure the connection, define entities, and optionally add repositories. section 7.6.1

Configure the persistence layer with these decisions:

  • Provide the MongoDB connection string; also configure the database name unless entities specify it with @MongoEntity. section 7.6.1
  • Extend PanacheMongoEntity for an automatically supplied identifier, or PanacheMongoEntityBase when declaring a custom identifier. section 7.6.1
  • Use PanacheMongoRepository or PanacheMongoRepositoryBase when choosing the repository pattern or changing identifier types. section 7.6.1

Persisting rentals through an active-record entity

A Rental entity stores userId, reservationId, dates, and active state. Static methods find a rental by user and reservation or list active rentals. A REST resource creates a rental, calls persist(), then updates and persists an existing rental when ending it.

Development mode starts MongoDB through Dev Services when the production connection property is undefined. Verify the service with HTTP requests or inspect the stored document using mongosh; a fixed Dev Services port is optional. section 7.6.2

How Quarkus in Action covers it

How deep it goes
Defines installation, configuration, entity bases, queries, persistence, REST updates, and verification; defers transactions as unnecessary for the example.
Examples
Demonstrates a Rental entity, active-rental queries, start and end endpoints, HTTP calls, and mongosh document inspection.
What it assumes
Assumes a Quarkus service with REST resources and basic entity development; teaches the MongoDB-specific Panache integration steps.
What you can do after
Build it from scratch by adding the extension, configuring MongoDB, defining Panache entities, persisting records, and verifying documents.
How it connects
Connects Panache, MongoDB entities, repositories, JAX-RS resources, REST, and Dev Services.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Quarkus in Action. The section links point to the parts of the book it draws on.