Skip to content

Add Spring Data + Document DB Playground - #6

Open
hossain-rayhan wants to merge 1 commit into
documentdb:mainfrom
hossain-rayhan:rayhan/spring-data
Open

Add Spring Data + Document DB Playground#6
hossain-rayhan wants to merge 1 commit into
documentdb:mainfrom
hossain-rayhan:rayhan/spring-data

Conversation

@hossain-rayhan

Copy link
Copy Markdown
Collaborator

Add Spring Data MongoDB playground (Java)

Summary

Adds a fifth playground — spring-data-mongodb — demonstrating Spring Boot + Spring Data MongoDB (Java) against a local DocumentDB emulator. This extends the repository into the JVM ecosystem, complementing the existing Node.js (Mongoose / native driver) and Python (Beanie / PyMongo) playgrounds. It follows the exact structure and conventions of the existing playgrounds.

What's included

  • Lifecycle scripts (scripts/) mirroring the other playgrounds — lib.sh, start-documentdb.sh, stop-documentdb.sh, run-app.sh, run-test.sh — adapted to a Maven/JDK toolchain (instead of npm/venv), including a resolve_maven helper that prefers ./mvnw and falls back to system mvn.
  • Spring Boot demo API exposing the same surface as the sibling playgrounds:
    • Book @Document model with a compound index and @CreatedDate/@LastModifiedDate auditing
    • BookRepository (MongoRepository) with a derived query
    • REST endpoints: POST/GET/PATCH/DELETE /books, GET /books/{id}, GET /stats/genres (aggregation), GET /health
  • Standalone 16-step compatibility suite (CrudCompatibilityTest) using MongoTemplate: connect, index creation, insert (single/many), findById, filtered/sorted queries, count, update, findAndModify, aggregation, unique-index enforcement, delete, and $vectorSearch.
  • Documentation: a playground README.md matching the house style, plus updates to the root README.md (playground table, quick-start example, repository layout).

Java-specific TLS handling

Unlike the Node.js/Python drivers, the MongoDB Java driver has no connection-string option to accept a self-signed certificate — tlsInsecure only disables hostname verification, not certificate-chain validation. To connect to the emulator's self-signed cert, MongoClientFactory installs a trust-all SSLContext (gated by TLS_INSECURE) and strips replicaSet / tlsAllowInvalidCertificates from the shared connection string. For production, set TLS_INSECURE=false and configure a truststore with the server's CA.

Validation

  • mvn compile succeeds.
  • Compatibility suite prints Passed: 16 Failed: 0 against documentdb-local:latest.
  • Demo API verified manually: /health returns healthy, book creation populates auditing timestamps + generated id, listing works, and /stats/genres aggregation returns expected results.

How to try it

cd playgrounds/spring-data-mongodb
./scripts/run-test.sh   # start DocumentDB locally and run the compatibility suite
./scripts/run-app.sh    # or run the demo REST API on :3000

Prerequisites: Docker, JDK 17+, and Maven.

Signed-off-by: Rayhan Hossain <hossain.rayhan@outlook.com>
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.

1 participant