Skip to content

Commit 17bc8f7

Browse files
committed
Clarify MongoDB job repository configuration in reference documentation
Resolves #4859
1 parent acc48a3 commit 17bc8f7

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

spring-batch-docs/modules/ROOT/pages/job/configuring-repository.adoc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ of the various persisted domain objects within Spring Batch, such as `JobExecuti
66
It is required by many of the major framework features, such as the `JobOperator`,
77
`Job`, and `Step`.
88

9+
== Configuring a JDBC JobRepository
10+
911
[tabs]
1012
====
1113
Java::
@@ -68,6 +70,29 @@ The `max-varchar-length` defaults to `2500`, which is the length of the long
6870
`VARCHAR` columns in the xref:schema-appendix.adoc#metaDataSchemaOverview[sample schema scripts].
6971
====
7072

73+
== Configuring a MongoDB JobRepository
74+
75+
Similar to the JDBC-based `JobRepository`, the MongoDB-based `JobRepository` requires some collections
76+
to store the batch metadata. These collections are defined in the `org/springframework/batch/core/schema-mongodb.jsonl`
77+
of the `spring-batch-core` jar. As with the JDBC-based `JobRepository`, you need to create these collections
78+
in your MongoDB database before running any job.
79+
80+
Moreover, since it is https://www.mongodb.com/docs/manual/core/dot-dollar-considerations/[not recommended] to use `.` in
81+
field names in MongoDB documents, you need to customize the `MongoTemplate` used by the `MongoJobRepositoryFactoryBean`
82+
to replace `.` with another character (for example, `_`) in the field names. You can do this by customizing the `MappingMongoConverter`
83+
used by the `MongoTemplate`. The following example shows how to do this in Java configuration:
84+
85+
.Java Configuration
86+
[source, java]
87+
----
88+
@Bean
89+
public MongoTemplate mongoTemplate(MongoDatabaseFactory mongoDatabaseFactory) {
90+
MongoTemplate template = new MongoTemplate(mongoDatabaseFactory);
91+
MappingMongoConverter converter = (MappingMongoConverter) template.getConverter();
92+
converter.setMapKeyDotReplacement("_");
93+
return template;
94+
}
95+
----
7196

7297
[[txConfigForJobRepository]]
7398
== Transaction Configuration for the JobRepository

0 commit comments

Comments
 (0)