{"id":18398578,"url":"https://github.com/mongodb-developer/mdb-spring-boot-reactive","last_synced_at":"2025-08-21T03:13:26.657Z","repository":{"id":228413537,"uuid":"768419255","full_name":"mongodb-developer/mdb-spring-boot-reactive","owner":"mongodb-developer","description":"Reactive Java Spring Boot with Spring Data MongoDB ","archived":false,"fork":false,"pushed_at":"2024-07-18T21:07:43.000Z","size":28,"stargazers_count":7,"open_issues_count":1,"forks_count":5,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-07T04:34:08.010Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mongodb-developer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-07T03:32:43.000Z","updated_at":"2025-04-03T13:38:40.000Z","dependencies_parsed_at":"2024-03-22T20:48:50.950Z","dependency_job_id":"c6ccb200-677a-4a9c-afba-c5ae17ddb3f4","html_url":"https://github.com/mongodb-developer/mdb-spring-boot-reactive","commit_stats":null,"previous_names":["mongodb-developer/mdb-spring-boot-reactive"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mongodb-developer/mdb-spring-boot-reactive","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodb-developer%2Fmdb-spring-boot-reactive","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodb-developer%2Fmdb-spring-boot-reactive/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodb-developer%2Fmdb-spring-boot-reactive/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodb-developer%2Fmdb-spring-boot-reactive/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mongodb-developer","download_url":"https://codeload.github.com/mongodb-developer/mdb-spring-boot-reactive/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodb-developer%2Fmdb-spring-boot-reactive/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271420152,"owners_count":24756490,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-21T02:00:08.990Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T02:22:50.326Z","updated_at":"2025-08-21T03:13:26.640Z","avatar_url":"https://github.com/mongodb-developer.png","language":"Java","readme":"# Reactive Java Spring Boot with Spring Data MongoDB \n\n## About\nA simplified cash balance application built with reactive Java Spring Boot and Spring Data MongoDB. This project showcases:\n- Create, Read and Updates with ReactiveMongoRepository\n- Create, Read and Updates with ReactiveMongoTemplate\n- Wrapping queries in a multi-document transaction\n\n## Supported Versions\n- Java 21\n- Spring Boot Starter Webflux 3.2.3 \n- Spring Boot Starter Reactive Data Mongodb 3.2.3\n\n## How it should work\n1. A bank account can be created with a unique accountNum, and it always starts with a balance of $0.\n2. Accounts and their balances are saved in the \"accounts\" collection.\n3. A debit operation adds to the balance of the account.\n4. A credit operation deducts from the balance of the account.\n5. A transfer operation deducts from the balance of one account and adds to another.\n6. A successful transaction flow is as follows:\n   1. Debit/Credit/Transfer operations are first saved in the \"transactions\" collection with status \"PENDING\"\n   2. The balances of each account is updated accordingly\n   3. The transaction status is then updated to \"SUCCESS\"\n7. If there is insufficient balance for deduction in an account, the transaction is rolled back and the status of the transaction is updated to \"FAILED\"\n8. If the account number cannot be found, the transaction is rolled back and the status of the transaction is updated to \"FAILED\"\n\n## Initialization and Setup\n1. Ensure you have access to a MongoDB cluster\n2. Run the following to set up schema validation. This creates a constraint such that the \"balance\" should never be less than 0.\n```shell\nmongosh \"\u003cMongoDB connection string\u003e\" --file setup.js\n```\n3. Create application.properties file in resources and add the following lines \n```properties\nspring.data.mongodb.uri=\u003cMongoDB connection string\u003e\nspring.data.mongodb.database=txn-demo\n ```\n4. Run `mvn clean compile` to compile\n5. Run `mvn spring-boot:run` to run the application\n\n## API Usage\n\n### Create account\nPOST /account \\\nRequest Body:\n```\n{\n  accountNum: \u003cString\u003e,\n  balance: \u003cNumber\u003e\n}\n```\nExample:\n```shell\ncurl --location 'localhost:8080/account' \\\n--header 'Content-Type: application/json' \\\n--data '{\n    \"accountNum\": \"111111\"\n}'\n```\n\n### Get account\nGET /account/{accountNum}\nExample:\n```shell\ncurl --location 'localhost:8080/account/111111'\n```\n\n### Debit to account\nPOST /account/{accountNum}/debit \\\nRequest Body:\n```\n{\n  amount: \u003cNumber\u003e\n}\n```\nExample:\n```shell\ncurl --location 'localhost:8080/account/111111/debit' \\\n--header 'Content-Type: application/json' \\\n--data '{\n    \"amount\": 1000\n}'\n```\n\n### Credit from account\nPOST /account/{accountNum}/credit \\\nRequest Body:\n```\n{\n  amount: \u003cNumber\u003e\n}\n```\nExample:\n```shell\ncurl --location 'localhost:8080/account/111111/credit' \\\n--header 'Content-Type: application/json' \\\n--data '{\n    \"amount\":10000\n}'\n```\n\n### Transfer to another account\nPOST /account/{accountNum}/transfer \\\nRequest Body:\n```\n{\n  to: \u003cString\u003e\n  amount: \u003cNumber\u003e\n}\n```\nExample:\n```shell\ncurl --location 'localhost:8080/account/123456/transfer' \\\n--header 'Content-Type: application/json' \\\n--data '{\n    \"to\": \"1111111\",\n    \"amount\": 500\n}'\n```\n\n## Postman Test Collection\nThe Postman Test Collection is meant for a high-level functional test to ensure that the APIs are still functionally correct.\nThe Postman calls are meant to be run in sequence and the database needs to be in a clean slate (see step 3).\nTo run the test:\n1. Import the collection into Postman\n2. In Postman, add environment variables \"host\" and \"port\"\n3. In command line, run `mongosh \"\u003cMongoDB connection string\u003e\" --file setup.js` to reset the database.\n4. Use Postman to \"Run collection\" to automatically run all the Postman calls in sequence and see that the tests are passing.\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmongodb-developer%2Fmdb-spring-boot-reactive","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmongodb-developer%2Fmdb-spring-boot-reactive","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmongodb-developer%2Fmdb-spring-boot-reactive/lists"}