Skip to content

Conversation

SHINMH
Copy link

@SHINMH SHINMH commented Oct 16, 2025

📝 Description
This PR adds collection prefix support for MongoDB job repository, mirroring the existing tablePrefix functionality in JDBC job repository. This enables multi-application support, environment isolation, and easier management of MongoDB collections in Spring Batch deployments.

🎯 Motivation
Currently, MongoDB job repository uses hardcoded collection names (BATCH_JOB_INSTANCE, BATCH_JOB_EXECUTION, etc.), making it difficult to:

Run multiple Spring Batch applications against the same MongoDB database
Isolate different environments (dev, test, prod)
Manage collections with custom naming conventions

🔧 Changes
EnableMongoJobRepository: Add collectionPrefix parameter (defaults to "BATCH_")
MongoJobRepositoryFactoryBean: Add collection prefix support
MongoDB DAO classes: Support configurable collection names via constructor parameters
BatchRegistrar: Pass collection prefix from annotation to factory bean
Tests: Add integration tests for collection prefix functionality

💡 Usage Example

@EnableBatchProcessing
@EnableMongoJobRepository(collectionPrefix = "MY_APP_")
public class BatchConfiguration {
    // Configuration
}

This will create collections like:
MY_APP_JOB_INSTANCE
MY_APP_JOB_EXECUTION
MY_APP_STEP_EXECUTION

Closes: collectionPrefix for MongoDB Job repository #4980

@SHINMH SHINMH changed the title dd collection prefix support for MongoDB job repository MongoDB collection prefix support for MongoDB job repository Oct 16, 2025
- Add collectionPrefix parameter to EnableMongoJobRepository annotation
- Update MongoDB DAO classes to support configurable collection names
- Maintain backward compatibility with default "BATCH_" prefix

Signed-off-by: Myeongha Shin <[email protected]>
@SHINMH SHINMH changed the title MongoDB collection prefix support for MongoDB job repository Collection prefix support for MongoDB job repository Oct 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

collectionPrefix for MongoDB Job repository

1 participant