Quarkus supports a feature called Dev Services that allows you to create various datasources without any config. In the case of MongoDB this support extends to the default MongoDB connection.
What that means practically, is that if you have not configured quarkus.mongodb.connection-string
nor quarkus.mongodb.hosts
, Quarkus will automatically start a MongoDB container when
running tests or in dev mode, and automatically configure the connection.
MongoDB Dev Services is based on Testcontainers MongoDB module that will start a single node replicaset.
When running the production version of the application, the MongoDB connection need to be configured as normal, so if you want to include a production database config in your
application.properties
and continue to use Dev Services we recommend that you use the %prod.
profile to define your MongoDB settings.
Shared server
Most of the time you need to share the server between applications. Dev Services for MongoDB implements a service discovery mechanism for your multiple Quarkus applications running in dev mode to share a single server.
Dev Services for MongoDB starts the container with the quarkus-dev-service-mongodb label which is used to identify the container.
|
If you need multiple (shared) servers, you can configure the quarkus.mongodb.devservices.service-name
attribute and indicate the server name.
It looks for a container with the same value, or starts a new one if none can be found.
The default service name is mongodb
.
Sharing is enabled by default in dev mode, but disabled in test mode.
You can disable the sharing with quarkus.mongodb.devservices.shared=false
.
Configuration reference
Configuration property fixed at build time - All other configuration properties are overridable at runtime
Configuration property |
Type |
Default |
---|---|---|
If DevServices has been explicitly enabled or disabled. DevServices is generally enabled by default, unless there is an existing configuration present. When DevServices is enabled Quarkus will attempt to automatically configure and start a database when running in Dev or Test mode. Environment variable: |
boolean |
|
The container image name to use, for container based DevServices providers. Environment variable: |
string |
|
Optional fixed port the dev service will listen to. If not defined, the port will be chosen randomly. Environment variable: |
int |
|
Generic properties that are added to the connection URL. Environment variable: |
Map<String,String> |
|
Environment variables that are passed to the container. Environment variable: |
Map<String,String> |
|
Indicates if the MongoDB server managed by Quarkus Dev Services is shared. When shared, Quarkus looks for running containers using label-based service discovery. If a matching container is found, it is used, and so a second one is not started. Otherwise, Dev Services for MongoDB starts a new container. The discovery uses the Container sharing is only used in dev mode. Environment variable: |
boolean |
|
The value of the Environment variable: |
string |
|