From f02338ef74158d22040cb61b2d1e81e353b90c7c Mon Sep 17 00:00:00 2001 From: kyvg <47474371+kyvg@users.noreply.github.com> Date: Tue, 2 Jun 2026 16:35:23 +0200 Subject: [PATCH] bump mongo db --- docker-compose.yml | 16 +++++++++++----- server/models/index.ts | 13 ++++++------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 942fe0cd..b39765cd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,17 +13,23 @@ services: env_file: - .env restart: always - links: - - "db" depends_on: - - db + db: + condition: service_healthy db: - image: mongo:4.4 + image: mongo:8.0 mem_limit: 512M cpu_percent: 60 restart: always + command: ["mongod", "--replSet", "rs0", "--auth"] environment: MONGO_INITDB_ROOT_USERNAME: root MONGO_INITDB_ROOT_PASSWORD: fworootpassword volumes: - - db:/data/db \ No newline at end of file + - db:/data/db + healthcheck: + test: | + mongosh --quiet --eval "try { rs.status().ok } catch(e) { 0 }" --authenticationDatabase admin -u root -p fworootpassword 2>/dev/null | grep -q 1 + interval: 10s + retries: 30 + start_period: 30s \ No newline at end of file diff --git a/server/models/index.ts b/server/models/index.ts index f4cb3a60..029a560b 100644 --- a/server/models/index.ts +++ b/server/models/index.ts @@ -1,7 +1,7 @@ import mongoose, { type ConnectOptions } from 'mongoose'; // MONGO - полный mongo uri: -// "mongodb://user:password@db:27017/fwo?retryWrites=true&w=majority&authSource=admin +// "mongodb://user:password@db:27017/fwo?retryWrites=true&w=majority&authSource=admin&replicaSet=rs0 mongoose.set('toObject', { virtuals: true }); @@ -16,19 +16,18 @@ export async function connect(onConnect?: () => void): Promise { switch (process.env.NODE_ENV) { case 'production': await mongoose.connect( - process.env.MONGO ?? 'mongodb://root:fworootpassword@db:27017/fwo', + process.env.MONGO ?? + 'mongodb://root:fworootpassword@db:27017/fwo?retryWrites=true&w=majority&authSource=admin&replicaSet=rs0', options, ); break; case 'test': - await mongoose.connect( - process.env.MONGO ?? 'mongodb://localhost:27017/test-fwo', - options, - ); + await mongoose.connect(process.env.MONGO ?? 'mongodb://localhost:27017/test-fwo', options); break; case 'development': await mongoose.connect( - process.env.MONGO ?? 'mongodb://root:fworootpassword@localhost:27017/fwo', + process.env.MONGO ?? + 'mongodb://root:fworootpassword@localhost:27017/fwo?retryWrites=true&w=majority&authSource=admin&replicaSet=rs0', options, ); break;