Convert MongoDB from standalone to replica set#4184
Closed
Conversation
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 standalone mode does not support multi-document transactions, which are required for atomic merge operations across
FrontierCollectionandMergeCollection. This converts to a single-member replica set (rs0) in both development and Docker/Kubernetes environments.Development (
npm start)scripts/startDatabase.js(new): Replacespredatabase+databasenpm scripts and the now-removedsetupMongo.js. Spawnsmongod --replSet rs0, polls until ready, callsrs.initiate(), then stays alive until mongod exits. Failures are fatal: SIGINT/SIGTERM handlers are registered early, startup/init failures callprocess.exit(1), and mongod's exit code is propagated viaprocess.exit(exitCode ?? 1).scripts/setupMongo.js(removed): No longer needed; its directory-creation logic is handled bystartDatabase.js.package.json:databasescript →node scripts/startDatabase.js;predatabaseremoved..gitignore: ReplacedsetupMongo.jsexception withstartDatabase.jsexception.Docker / Kubernetes
database/init/00-replica-set.js(new): Placed in/docker-entrypoint-initdb.d/, runs on first container startup. Callsrs.initiate()with a configurable advertised hostname viaMONGO_INITDB_REPLICA_HOST(defaults tolocalhost:27017). Waits up to 30s for PRIMARY election before allowing subsequent init scripts to run.database.yaml(Kubernetes Helm): Addsargs: ["--replSet", "rs0"]and setsMONGO_INITDB_REPLICA_HOSTto the pod IP so the replica set member hostname is tracked per pod. The postStart lifecycle hook initializes the replica set on first start and reconfigures the member host (rs.reconfig) when the pod IP changes after a restart, keeping the replica set config in sync.Configuration
appsettings.json: Connection strings now explicitly include?replicaSet=rs0..vscode/tasks.json:run-mongotask updated to invokenpm run database(which runsscripts/startDatabase.js) instead of callingmongoddirectly, ensuring replica set initialization is performed automatically on first run.README.md: MongoDB Compass connection string updated tomongodb://localhost:27017/?replicaSet=rs0.✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.
This change is
Summary by CodeRabbit
New Features
Documentation