feat(persistence): MongoDB backend with CRUD, search, history, and transactions#44
Open
doug-helios wants to merge 17 commits intomainfrom
Open
feat(persistence): MongoDB backend with CRUD, search, history, and transactions#44doug-helios wants to merge 17 commits intomainfrom
doug-helios wants to merge 17 commits intomainfrom
Conversation
…nal operations Add search_index collection with 11 specialized indexes for FHIR search parameters (string, token, date, number, quantity, reference, uri, composite, resource, token_display, identifier_type). Implement SearchProvider with cursor-based pagination, sort support, and count queries. Add ConditionalStorage for conditional create/update/delete with search parameter matching. Bump schema version to 4.
…pagination tests Add 6 new integration tests covering search parameter registration/unregistration on create/update/delete (active/draft/retired status handling) and bidirectional cursor-based pagination with has_next/has_previous flags. Tests verify registry state changes and cursor roundtrip navigation.
…test coverage Update roadmap status from planned to completed for phases 2-4 (core storage parity, versioning/history/conditional semantics, search/indexing/conditional operations). Update last_updated to 2026-03-09 and progress summary to reflect full implementation and validation through MongoDB integration tests.
Add MongoDB standalone and MongoDB+Elasticsearch composite modes to HFS server. Implement start_mongodb() and start_mongodb_elasticsearch() functions with connection string/env detection, schema initialization, and search offloading. Add empty Elasticsearch node validation for all composite modes. Update documentation to reflect MongoDB Phase 5 completion (CRUD, versioning, search, conditional ops, composite integration). Add El
…ntation Update ROADMAP.md to reflect MongoDB standalone and MongoDB+Elasticsearch as shipped persistence options. Update persistence README with MongoDB runtime configuration examples, architecture tree, and search offloading documentation. Add phase6_roadmap.xml as detailed closure artifact. Update roadmap_mongo.xml to reference completed Phase 5/6 artifacts and synchronize progress statements across all roadmap documents.
…bundle support Add MongoDB to Inferno workflow matrix alongside sqlite/postgres backends. Implement MongoDB replica set initialization with 60s primary election timeout and container lifecycle management. Add transaction bundle support to MongoDB backend with ClientSession-based ACID semantics, reference resolution, SearchParameter registry integration, and rollback on entry failures. Declare Transactions capability in backend
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MongoDB Persistence Backend - Complete Implementation
Overview
This PR introduces MongoDB as a fully-featured primary persistence backend for the Helios FHIR Server (HFS), delivering production-ready FHIR storage capabilities with comprehensive search, versioning, history, conditional operations, and composite Elasticsearch integration.
Summary
MongoDB support has been implemented through a structured 6-phase roadmap plus transaction-bundle parity work, progressing from initial scaffolding to full Inferno test suite validation. The implementation provides:
Implementation Phases
Phase 1: Backend Skeleton and Feature Wiring ✅
Goal: Establish compile-time and runtime hooks for MongoDB backend
Delivered:
crates/persistence/src/backends/mongodb/Files:
crates/persistence/src/backends/mongodb/mod.rscrates/persistence/src/backends/mongodb/backend.rscrates/persistence/src/backends/mongodb/config.rscrates/persistence/src/backends/mongodb/schema.rsPhase 2: Core Storage Contract Parity ✅
Goal: Achieve minimum ResourceStorage parity with SQLite/PostgreSQL
Delivered:
crates/persistence/tests/mongodb_tests.rs)Key Features:
Phase 3: Versioning, History, and Transaction Semantics ✅
Goal: Implement FHIR version/history semantics with session-based consistency
Delivered:
Key Decisions:
Phase 4: Search, Indexing, and Conditional Semantics ✅
Goal: Enable FHIR search and conditional operations with native MongoDB indexing
Delivered:
Files:
crates/persistence/src/backends/mongodb/search_impl.rscrates/persistence/src/backends/mongodb/storage.rsBoundaries:
Phase 5: Composite Integration (MongoDB + Elasticsearch) ✅
Goal: Provide robust primary-secondary mode mirroring existing composite backends
Delivered:
Runtime Configuration:
Files:
crates/persistence/src/backends/composite/(updated for MongoDB)crates/rest/src/config.rs(mongodb-elasticsearch mode)crates/hfs/src/main.rs(startup wiring)Phase 6: Server Wiring, Documentation, and Release Readiness ✅
Goal: Expose MongoDB modes to HFS runtime with complete documentation
Delivered:
MongoDBandMongoDBElasticsearchvariantsstart_mongodb()andstart_mongodb_elasticsearch()HFS_STORAGE_BACKEND=mongodbormongodb-elasticsearchHFS_DATABASE_URL=mongodb://...crates/persistence/README.mdcapability matrixROADMAP.mdpersistence sectionConfiguration Example:
Final Phase: Transaction-Bundle Parity and Inferno Validation ✅
Goal: Enable MongoDB in full Inferno test matrix with transaction-bundle support
Delivered:
rs.initiate())mongodb://localhost:27017/?replicaSet=rs0&directConnection=trueFiles:
crates/persistence/src/backends/mongodb/storage.rs(process_transaction).github/workflows/inferno.yml(replica-set topology)crates/persistence/tests/mongodb_tests.rs(transaction coverage)Capability Matrix
Testing Coverage
Unit Tests
Integration Tests
CI Coverage
Architecture
Data Model
Resources Collection:
History Collection:
Search Indexes Collection (when not offloaded):
Indexes
{tenant_id: 1, resource_type: 1, resource_id: 1}(unique, active resources){tenant_id: 1, resource_type: 1, resource_id: 1, version_id: 1}(history){tenant_id: 1, resource_type: 1, last_updated: -1}(type history){tenant_id: 1, last_updated: -1}(system history)Configuration
Standalone MongoDB
MongoDB + Elasticsearch Composite
Transaction Support (Replica Set)
Migration Path
Existing deployments can adopt MongoDB incrementally:
Breaking Changes
None. MongoDB is an additive backend option. Existing SQLite and PostgreSQL deployments are unaffected.
Documentation Updates
crates/persistence/README.md- Capability matrix and MongoDB statusROADMAP.md- Persistence roadmap with MongoDB phasescrates/rest/src/config.rs- Configuration documentationphase2_roadmap.xmlthroughphase6_roadmap.xml,final_roadmap.xml)roadmap_mongo.xml)Validation
All validation commands pass:
Roadmap Artifacts
Detailed planning and execution tracking:
roadmap_mongo.xml- Umbrella 6-phase roadmap (completed)phase2_roadmap.xml- Core storage parity (completed)phase3_roadmap.xml- Versioning and history (completed)phase4_roadmap.xml- Search and conditional ops (completed)phase5_roadmap.xml- Composite integration (completed)phase6_roadmap.xml- Runtime wiring (completed)final_roadmap.xml- Transaction-bundle parity (completed)Future Work
Planned enhancements (out of scope for this PR):
Contributors
Implementation followed structured phase-based delivery with comprehensive testing, documentation, and CI integration at each milestone.
Related Issues
Closes: [MongoDB persistence backend tracking issue]