This version is still in development and is not considered stable yet. For the latest stable version, please use Spring Cloud Config 4.1.4!

MongoDB Backend

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.

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:

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:

{
  "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.)

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.