Dev Services for MongoDB
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.
O MongoDB Dev Services é baseado no módulo Testcontainers MongoDB que iniciará um conjunto de réplicas de nó único.
Ao executar a versão de produção do aplicativo, a conexão do MongoDB precisa ser configurada normalmente, portanto, se quiser incluir uma configuração de banco de dados de produção no seu application.properties e continuar a usar o Dev Services, recomendamos que use o perfil %prod. para definir as configurações do MongoDB.
Servidor compartilhado
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.
Compose
The MongoDB Dev Services supports Compose Dev Services.
It relies on a compose-devservices.yml, such as:
name: <application name>
services:
mongo:
image: docker.io/mongo:7.0
ports:
- "27017"