From e04a9dd3b110cf258b84e4f5de97e29b2618d300 Mon Sep 17 00:00:00 2001 From: Kfir Dayan Date: Thu, 20 Apr 2023 18:52:55 +0300 Subject: [PATCH] pushing for testing mongoDB --- .env.example | 6 ++++++ docker-compose.yaml | 12 ++++++++---- src/app.module.ts | 4 ++-- 3 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..964dbdf --- /dev/null +++ b/.env.example @@ -0,0 +1,6 @@ +## DB [MongoDb](https://www.mongodb.com/) ## +MONGO_USERNAME=akamai +MONGO_PASSWORD=password +MONGO_DATABASE=mydatabase +MONGO_HOST=mongo +MONGO_PORT=27017 \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index 501e3de..f9446f3 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -7,15 +7,19 @@ services: depends_on: - mongo environment: - - MONGO_URL=mongodb://mongo:27017/mydatabase + - MONGO_USERNAME=${MONGO_USERNAME} + - MONGO_PASSWORD=${MONGO_PASSWORD} + - MONGO_HOST=${MONGO_HOST} + - MONGO_PORT=${MONGO_PORT} + - MONGO_DATABASE=${MONGO_DATABASE} networks: - appnet mongo: image: mongo environment: - - MONGO_INITDB_DATABASE=mydatabase - - MONGO_INITDB_ROOT_USERNAME=akamai - - MONGO_INITDB_ROOT_PASSWORD=password + - MONGO_INITDB_DATABASE=${MONGO_DATABASE} + - MONGO_INITDB_ROOT_USERNAME=${MONGO_USERNAME} + - MONGO_INITDB_ROOT_PASSWORD=${MONGO_PASSWORD} volumes: - dbdata:/data/db networks: diff --git a/src/app.module.ts b/src/app.module.ts index c8604bc..bc42598 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -5,10 +5,10 @@ import { CrawlerModule } from './crawler/crawler.module'; const dotenv = require('dotenv'); dotenv.config(); - +console.log("mongodb://" + process.env.MONGO_USERNAME + ":" + process.env.MONGO_PASSWORD + "@" + process.env.MONGO_HOST + ":" + process.env.MONGO_PORT); @Module({ imports: [ - MongooseModule.forRoot(process.env.MONGO_URL, { + MongooseModule.forRoot("mongodb://" + process.env.MONGO_USERNAME + ":" + process.env.MONGO_PASSWORD + "@" + process.env.MONGO_HOST + ":" + process.env.MONGO_PORT, { useNewUrlParser: true, useUnifiedTopology: true, }),