feat(config-server): add MongoDB environment repository support (#2390)

* feat(config-server): add MongoDB environment repository support

This commit introduces MongoDB as a new backend option for the Spring Cloud Config Server, enabling users to store and manage their configuration properties in a MongoDB database.

* resolve pr comments

* add documentation for mongodb backend

* resolve comments
This commit is contained in:
Alexandros Pappas
2024-10-02 20:36:29 +02:00
committed by GitHub
parent 3c69958559
commit 634f46b424
10 changed files with 699 additions and 1 deletions

View File

@@ -15,6 +15,7 @@
*** xref:server/environment-repository/aws-parameter-store-backend.adoc[]
*** xref:server/environment-repository/aws-secrets-manager-backend.adoc[]
*** xref:server/environment-repository/credhub-backend.adoc[]
*** xref:server/environment-repository/mongo-backend.adoc[]
*** xref:server/environment-repository/composite-repositories.adoc[]
*** xref:server/environment-repository/custom-enviroment-repository.adoc[]
*** xref:server/environment-repository/property-overrides.adoc[]

View File

@@ -0,0 +1,58 @@
[[mongo-backend]]
= MongoDB Backend
:page-section-summary-toc: 1
Spring Cloud Config Server supports MongoDB as a backend for configuration properties.
You can enable this feature by adding `spring-boot-starter-data-mongodb` to the classpath and using the `mongodb` profile.
[source,xml,indent=0]
.pom.xml
----
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
</dependencies>
----
Configure your application's `application.properties` or `application.yml` to point to your MongoDB instance:
[source,yaml]
----
spring:
profiles:
active: mongodb
data:
mongodb:
database: your-database-name
port: '27017'
host: localhost
----
The configuration properties should be stored in documents within the `properties` collection. Each document represents a set of properties for a given application, profile, and label.
Example MongoDB document:
[source,json]
----
{
"application": "myapp",
"profile": "development",
"label": "master",
"properties": {
"property1": "value1",
"property2": "value2"
}
}
----
You can disable autoconfiguration for `MongoDbEnvironmentRepository` by setting the `spring.cloud.config.server.mongodb.enabled` property to `false`.
The default values for MongoDB backend configuration are as follows:
- **Collection Name:** `"properties"` (Name of the MongoDB collection to query for configuration properties.)
- **Default Label:** `"master"` (Default label to use if none is specified.)
NOTE: You can change these defaults by setting `spring.cloud.config.server.mongodb.collection` and `spring.cloud.config.server.mongodb.defaultLabel` in your application's configuration.