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 {
2525 const client = new MongoClient ( config . get ( 'mongo.url' ) , { useUnifiedTopology : true } ) ;
2626
2727 await client . connect ( ) ;
28- client . db ( config . get ( 'mongo.name' ) ) ;
2928
3029 return client ;
3130 }
Original file line number Diff line number Diff line change @@ -12,11 +12,6 @@ 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'
2015 }
2116 }
2217} ) ;
Original file line number Diff line number Diff line change 11{
2- "mongo" : { "url" : " mongodb://localhost:27017" , "name" : " test" }
2+ "mongo" : { "url" : " mongodb://localhost:27017/ test" }
33}
Original file line number Diff line number Diff line change @@ -7,7 +7,19 @@ export class MongoEnvironmentArranger extends EnvironmentArranger {
77 }
88
99 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 ( ) ;
1123 }
1224
1325 protected client ( ) : Promise < MongoClient > {
You can’t perform that action at this time.
0 commit comments