@@ -31,6 +31,22 @@ const MongoClient = mongodb.MongoClient;
3131const ReadPreference = mongodb . ReadPreference ;
3232
3333const MongoSchemaCollectionName = '_SCHEMA' ;
34+
35+ const storageAdapterAllCollections = mongoAdapter => {
36+ return mongoAdapter . connect ( )
37+ . then ( ( ) => mongoAdapter . database . collections ( ) )
38+ . then ( collections => {
39+ return collections . filter ( collection => {
40+ if ( collection . namespace . match ( / \. s y s t e m \. / ) ) {
41+ return false ;
42+ }
43+ // TODO: If you have one app with a collection prefix that happens to be a prefix of another
44+ // apps prefix, this will go very very badly. We should fix that somehow.
45+ return ( collection . collectionName . indexOf ( mongoAdapter . _collectionPrefix ) == 0 ) ;
46+ } ) ;
47+ } ) ;
48+ }
49+
3450const convertParseSchemaToMongoSchema = ( { ...schema } ) => {
3551 delete schema . fields . _rperm ;
3652 delete schema . fields . _wperm ;
@@ -297,9 +313,10 @@ export class MongoStorageAdapter implements StorageAdapter {
297313 . catch ( err => this . handleError ( err ) ) ;
298314 }
299315
300- dropDatabase ( ) {
301- if ( ! this . database ) { return Promise . resolve ( ) ; }
302- return this . database . dropDatabase ( ) ;
316+ deleteAllClasses ( fast : boolean ) {
317+ return storageAdapterAllCollections ( this )
318+ . then ( collections => Promise . all ( collections . map ( collection => fast ? collection . remove ( { } ) : collection . drop ( ) ) ) )
319+ . catch ( err => this . handleError ( err ) ) ;
303320 }
304321
305322 // Remove the column and all the data. For Relations, the _Join collection is handled
0 commit comments