File tree Expand file tree Collapse file tree 4 files changed +14
-8
lines changed
Contexts/Shared/infrastructure/persistence/mongo
tests/Contexts/Shared/infrastructure/arranger Expand file tree Collapse file tree 4 files changed +14
-8
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,6 @@ export class MongoClientFactory {
25
25
const client = new MongoClient ( config . get ( 'mongo.url' ) , { useUnifiedTopology : true } ) ;
26
26
27
27
await client . connect ( ) ;
28
- client . db ( config . get ( 'mongo.name' ) ) ;
29
28
30
29
return client ;
31
30
}
Original file line number Diff line number Diff line change @@ -12,11 +12,6 @@ const convictConfig = convict({
12
12
doc : 'The Mongo connection URL' ,
13
13
format : String ,
14
14
env : 'MONGO_URL'
15
- } ,
16
- name : {
17
- doc : 'The Mongo database name' ,
18
- format : String ,
19
- env : 'MONGO_DB_NAME'
20
15
}
21
16
}
22
17
} ) ;
Original file line number Diff line number Diff line change 1
1
{
2
- "mongo" : { "url" : " mongodb://localhost:27017" , "name" : " test" }
2
+ "mongo" : { "url" : " mongodb://localhost:27017/ test" }
3
3
}
Original file line number Diff line number Diff line change @@ -7,7 +7,19 @@ export class MongoEnvironmentArranger extends EnvironmentArranger {
7
7
}
8
8
9
9
protected async clean ( name : string ) : Promise < void > {
10
- await ( await this . client ( ) ) . db ( ) . dropCollection ( name ) ;
10
+ const hasCollection = await this . hasCollection ( name ) ;
11
+
12
+ if ( hasCollection ) {
13
+ await ( await this . client ( ) ) . db ( ) . dropCollection ( name ) ;
14
+ }
15
+ }
16
+
17
+ private async hasCollection ( name : string ) : Promise < boolean > {
18
+ const client = await this . client ( ) ;
19
+ return await client
20
+ . db ( )
21
+ . listCollections ( { name } , { nameOnly : true } )
22
+ . hasNext ( ) ;
11
23
}
12
24
13
25
protected client ( ) : Promise < MongoClient > {
You can’t perform that action at this time.
0 commit comments