Skip to content

Commit 29e316d

Browse files
committed
Create database if not exist
1 parent 1e3626b commit 29e316d

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

src/Contexts/Shared/infrastructure/persistence/mongo/MongoClientFactory.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export class MongoClientFactory {
2525
const client = new MongoClient(config.get('mongo.url'), { useUnifiedTopology: true });
2626

2727
await client.connect();
28+
client.db(config.get('mongo.name'));
2829

2930
return client;
3031
}

src/apps/mooc_backend/config/config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ const convictConfig = convict({
1212
doc: 'The Mongo connection URL',
1313
format: String,
1414
env: 'MONGO_URL'
15+
},
16+
name: {
17+
doc: 'The Mongo database name',
18+
format: String,
19+
env: 'MONGO_DB_NAME'
1520
}
1621
}
1722
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"mongo": { "url": "mongodb://localhost:27017/mongo" }
2+
"mongo": { "url": "mongodb://localhost:27017", "name": "test" }
33
}

0 commit comments

Comments
 (0)