Skip to content

Bug fix in bean wiring for mongoclient#729

Open
shoebjoarder wants to merge 7 commits into
mainfrom
issue/650-bug-in-bean-wiring-for-mongoclient
Open

Bug fix in bean wiring for mongoclient#729
shoebjoarder wants to merge 7 commits into
mainfrom
issue/650-bug-in-bean-wiring-for-mongoclient

Conversation

@shoebjoarder

Copy link
Copy Markdown
Contributor

No description provided.

@shoebjoarder shoebjoarder linked an issue May 13, 2026 that may be closed by this pull request
@coderabbitai

coderabbitai Bot commented May 13, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Rate limit exceeded

@shoebjoarder has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 31 minutes and 7 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 1c9b4d86-d25c-4e11-b5fd-2ebd95aa66fb

📥 Commits

Reviewing files that changed from the base of the PR and between f2ac242 and 6934e22.

⛔ Files ignored due to path filters (1)
  • openlap-indicatoreditor/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (5)
  • openlap-indicatoreditor/package.json
  • openlap-indicatoreditor/src/common/components/navigation-bar/navigation-bar.jsx
  • openlap-indicatoreditor/src/pages/landing-page/components/app-appbar.jsx
  • openlap-indicatoreditor/src/pages/landing-page/components/toggle-color-mode.jsx
  • openlap-indicatoreditor/src/pages/landing-page/utils/news-data.jsx

Walkthrough

MongoDB configuration consolidated to use URI-based connection strings with embedded database names. Primary and secondary Spring bean configurations refactored from abstract superclass inheritance to explicit bean declarations. Deployment manifests and application properties updated to provide versioned database names (openlap_v2, learninglocker_v2) in connection URIs. Supporting documentation and gitignore also updated.

Changes

MongoDB URI-based Configuration Migration

Layer / File(s) Summary
MongoDB URI properties configuration
openlap-analyticsframework/src/main/resources/application.properties
Application properties now configure spring.data.mongodb.primary.uri and spring.data.mongodb.secondary.uri with database names embedded in the URIs, removing separate *.database property overrides.
Primary MongoDB bean configuration
openlap-analyticsframework/src/main/java/com/openlap/configurations/PrimaryMongoConfig.java
PrimaryMongoConfig refactored to explicit @Primary beans (primaryMongoClient, primaryMongoDbFactory, primaryMongoTemplate) with database name parsed from the connection URI using ConnectionString.
Secondary MongoDB bean configuration
openlap-analyticsframework/src/main/java/com/openlap/configurations/SecondaryMongoConfig.java
SecondaryMongoConfig similarly refactored to explicit @Bean declarations using @Qualifier for bean wiring and extracting database name from the URI via ConnectionString.
Deployment environment variable configuration
.k8s/base/openlap-analyticsframework/web/deployment.yaml, openlap-analyticsframework/compose.yaml
Kubernetes and Docker Compose manifests updated to provide versioned MongoDB URIs (/openlap_v2, /learninglocker_v2) and remove separate database name environment variables.
Supporting updates
README.md, .gitignore
Node.js version bumped to v22.18.0 in setup guide; Aider-related files added to gitignore.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive No pull request description was provided by the author, making it impossible to assess whether the description relates to the changeset. Add a description explaining the bug being fixed, why the refactoring was necessary, and how the bean wiring changes resolve the issue.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Bug fix in bean wiring for mongoclient' accurately summarizes the main change: refactoring MongoDB client bean configuration across multiple configuration files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue/650-bug-in-bean-wiring-for-mongoclient

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@openlap-analyticsframework/src/main/java/com/openlap/configurations/PrimaryMongoConfig.java`:
- Around line 41-42: PrimaryMongoConfig currently calls new
SimpleMongoClientDbFactory(client, db) where db is obtained via new
ConnectionString(primaryUri).getDatabase(); validate that db is not null or
empty before creating the factory: call
ConnectionString(primaryUri).getDatabase(), check StringUtils.hasText(db) (or db
!= null && !db.isEmpty()), and if missing throw an IllegalArgumentException with
a clear message like "Database name must be specified in primaryUri" (do the
same validation pattern in SecondaryMongoConfig for its primary/secondaryUri and
corresponding factory creation). Ensure you reference
ConnectionString.getDatabase, primaryUri, SimpleMongoClientDbFactory,
PrimaryMongoConfig and SecondaryMongoConfig when making the changes.

In
`@openlap-analyticsframework/src/main/java/com/openlap/configurations/SecondaryMongoConfig.java`:
- Around line 33-34: The code currently calls new
ConnectionString(secondaryUri).getDatabase() and passes the result directly into
new SimpleMongoClientDbFactory(client, db); add a validation step after
ConnectionString.getDatabase() to ensure the returned db is not null/empty
(e.g., if getDatabase() == null || db.isBlank()) and if it is, throw an
IllegalArgumentException (or a clear IllegalStateException) with a message
referencing secondaryUri so startup failure is explicit; keep using
ConnectionString, secondaryUri, getDatabase(), client and
SimpleMongoClientDbFactory but ensure the factory is only created when a valid
database name is present.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7f5f4936-22b9-48d1-b646-a6e66bef763b

📥 Commits

Reviewing files that changed from the base of the PR and between e46a862 and f2ac242.

📒 Files selected for processing (7)
  • .gitignore
  • .k8s/base/openlap-analyticsframework/web/deployment.yaml
  • README.md
  • openlap-analyticsframework/compose.yaml
  • openlap-analyticsframework/src/main/java/com/openlap/configurations/PrimaryMongoConfig.java
  • openlap-analyticsframework/src/main/java/com/openlap/configurations/SecondaryMongoConfig.java
  • openlap-analyticsframework/src/main/resources/application.properties

Comment on lines +41 to +42
String db = new ConnectionString(primaryUri).getDatabase();
return new SimpleMongoClientDbFactory(client, db);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Search for usage patterns and documentation of ConnectionString.getDatabase() 
# and SimpleMongoClientDbFactory to confirm null handling behavior.

# Search for existing null checks on ConnectionString database extraction
rg -nP --type=java -C3 'ConnectionString.*getDatabase\(\)' -g '!**/test/**'

# Search for any validation of database names in MongoDB configuration
rg -nP --type=java -C3 'SimpleMongoClientDbFactory.*null|isEmpty' -g '!**/test/**'

Repository: ude-soco/openlap-official

Length of output: 50381


🏁 Script executed:

# Find the MongoDB driver version and related dependencies
fd -e pom.xml | head -5 | xargs grep -A2 -B2 "mongo" -i

Repository: ude-soco/openlap-official

Length of output: 53


🌐 Web query:

MongoDB Java Driver ConnectionString.getDatabase() null behavior

💡 Result:

The MongoDB Java Driver's ConnectionString.getDatabase method returns null when no database name is specified in the connection string. The method is annotated with @Nullable and documented simply as "Gets the database name", which explicitly allows for null if absent [1][2]. The connection string format is mongodb://[username:password@]host1[:port1]...[/database.collection][?options], where /database is optional and only relevant for authentication; if omitted, getDatabase yields null [2][3]. For example, "mongodb://localhost:27017" has no database part, so ConnectionString cs = new ConnectionString("mongodb://localhost:27017"); String db = cs.getDatabase; would give db == null. This behavior is consistent across driver versions including 5.4.0 [1], 4.0.1 [2], and 3.x [4][3]. Note that MongoClient.getDatabase(name) is separate and requires a provided name; ConnectionString.getDatabase only parses what's in the URI [5][6].

Citations:


🌐 Web query:

SimpleMongoClientDbFactory null database parameter Spring Data MongoDB

💡 Result:

The SimpleMongoClientDatabaseFactory (or SimpleMongoClientDbFactory) in Spring Data MongoDB requires a non-null, non-empty database name parameter in its constructors. Passing null for the database parameter results in an IllegalArgumentException, typically with a message like "Database name must not be null or empty" or "Parameter databaseName must not be null or empty" [1][2][3][4]. Key evidence from official sources: - Constructor javadoc: "@param databaseName must not be {@literal null} or empty." [1][2][3] - Source code explicitly documents this requirement and throws exceptions for validation failures [1]. - Common runtime error when misconfigured: "Factory method 'mongoDatabaseFactory' threw exception with message: Database name must not be empty" [4]. To avoid this: - Provide a valid database name, e.g., new SimpleMongoClientDatabaseFactory(mongoClient, "myDatabase") [5]. - When using spring.data.mongodb.uri, ensure it includes the database name at the end (e.g., mongodb://localhost:27017/myDatabase), as spring.data.mongodb.database may be ignored if uri is set [4]. - For connection strings without dbname, use MongoTemplate directly with explicit db selection or ensure config provides it [5][6].

Citations:


🏁 Script executed:

# Check if there are any test files that show expected behavior
fd -e java -path "*test*" | xargs rg -l "SimpleMongoClientDbFactory" 2>/dev/null | head -3

Repository: ude-soco/openlap-official

Length of output: 442


Add validation for database name in MongoDB URI.

ConnectionString.getDatabase() returns null if the database is not specified in the URI. According to Spring Data MongoDB documentation, passing null to SimpleMongoClientDbFactory throws IllegalArgumentException: "Database name must not be null or empty" at application startup. Validate that the database name is present in the primary MongoDB URI before creating the factory.

Proposed fix
   public MongoDbFactory primaryMongoDbFactory(`@Qualifier`("primaryMongoClient") MongoClient client) {

     String db = new ConnectionString(primaryUri).getDatabase();
+    if (db == null || db.isEmpty()) {
+      throw new IllegalStateException(
+          "Database name must be specified in primary MongoDB URI: " + primaryUri);
+    }
     return new SimpleMongoClientDbFactory(client, db);
   }

Note: The same issue exists in SecondaryMongoConfig.java at line 33.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
String db = new ConnectionString(primaryUri).getDatabase();
return new SimpleMongoClientDbFactory(client, db);
String db = new ConnectionString(primaryUri).getDatabase();
if (db == null || db.isEmpty()) {
throw new IllegalStateException(
"Database name must be specified in primary MongoDB URI: " + primaryUri);
}
return new SimpleMongoClientDbFactory(client, db);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@openlap-analyticsframework/src/main/java/com/openlap/configurations/PrimaryMongoConfig.java`
around lines 41 - 42, PrimaryMongoConfig currently calls new
SimpleMongoClientDbFactory(client, db) where db is obtained via new
ConnectionString(primaryUri).getDatabase(); validate that db is not null or
empty before creating the factory: call
ConnectionString(primaryUri).getDatabase(), check StringUtils.hasText(db) (or db
!= null && !db.isEmpty()), and if missing throw an IllegalArgumentException with
a clear message like "Database name must be specified in primaryUri" (do the
same validation pattern in SecondaryMongoConfig for its primary/secondaryUri and
corresponding factory creation). Ensure you reference
ConnectionString.getDatabase, primaryUri, SimpleMongoClientDbFactory,
PrimaryMongoConfig and SecondaryMongoConfig when making the changes.

Comment on lines +33 to +34
String db = new ConnectionString(secondaryUri).getDatabase();
return new SimpleMongoClientDbFactory(client, db);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Validate that the URI contains a database name before creating the factory.

ConnectionString.getDatabase() returns null if the database is not present in the URI. Passing null to SimpleMongoClientDbFactory will likely cause a runtime failure during application startup. Add validation to ensure the database name is present in the URI.

🛡️ Proposed fix to add validation
   public MongoDbFactory secondaryMongoDbFactory(
       `@Qualifier`("secondaryMongoClient") MongoClient client) {

     String db = new ConnectionString(secondaryUri).getDatabase();
+    if (db == null || db.isEmpty()) {
+      throw new IllegalStateException(
+          "Database name must be specified in secondary MongoDB URI: " + secondaryUri);
+    }
     return new SimpleMongoClientDbFactory(client, db);
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
String db = new ConnectionString(secondaryUri).getDatabase();
return new SimpleMongoClientDbFactory(client, db);
public MongoDbFactory secondaryMongoDbFactory(
`@Qualifier`("secondaryMongoClient") MongoClient client) {
String db = new ConnectionString(secondaryUri).getDatabase();
if (db == null || db.isEmpty()) {
throw new IllegalStateException(
"Database name must be specified in secondary MongoDB URI: " + secondaryUri);
}
return new SimpleMongoClientDbFactory(client, db);
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@openlap-analyticsframework/src/main/java/com/openlap/configurations/SecondaryMongoConfig.java`
around lines 33 - 34, The code currently calls new
ConnectionString(secondaryUri).getDatabase() and passes the result directly into
new SimpleMongoClientDbFactory(client, db); add a validation step after
ConnectionString.getDatabase() to ensure the returned db is not null/empty
(e.g., if getDatabase() == null || db.isBlank()) and if it is, throw an
IllegalArgumentException (or a clear IllegalStateException) with a message
referencing secondaryUri so startup failure is explicit; keep using
ConnectionString, secondaryUri, getDatabase(), client and
SimpleMongoClientDbFactory but ensure the factory is only created when a valid
database name is present.

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.

Bug in bean wiring for MongoClient

2 participants