@@ -10,6 +10,21 @@ let MongoClient = mongodb.MongoClient;
10
10
const MongoSchemaCollectionName = '_SCHEMA' ;
11
11
const DefaultMongoURI = 'mongodb://localhost:27017/parse' ;
12
12
13
+ const storageAdapterAllCollections = mongoAdapter => {
14
+ return mongoAdapter . connect ( )
15
+ . then ( ( ) => mongoAdapter . database . collections ( ) )
16
+ . then ( collections => {
17
+ return collections . filter ( collection => {
18
+ if ( collection . namespace . match ( / \. s y s t e m \. / ) ) {
19
+ return false ;
20
+ }
21
+ // TODO: If you have one app with a collection prefix that happens to be a prefix of another
22
+ // apps prefix, this will go very very badly. We should fix that somehow.
23
+ return ( collection . collectionName . indexOf ( mongoAdapter . _collectionPrefix ) == 0 ) ;
24
+ } ) ;
25
+ } ) ;
26
+ }
27
+
13
28
export class MongoStorageAdapter {
14
29
// Private
15
30
_uri : string ;
@@ -86,25 +101,8 @@ export class MongoStorageAdapter {
86
101
87
102
// Delete all data known to this adatper. Used for testing.
88
103
deleteAllSchemas ( ) {
89
- return this . _allCollections ( ) . then ( collections => {
90
- let promises = collections . map ( collection => collection . drop ( ) ) ;
91
- return Promise . all ( promises ) ;
92
- } ) ;
93
- }
94
-
95
- _allCollections ( ) {
96
- return this . connect ( )
97
- . then ( ( ) => this . database . collections ( ) )
98
- . then ( collections => {
99
- return collections . filter ( collection => {
100
- if ( collection . namespace . match ( / \. s y s t e m \. / ) ) {
101
- return false ;
102
- }
103
- //TODO: If you have one app with a collection prefix that happens to be a prefix of another
104
- // apps prefix, this will go very very badly. We should fix that somehow.
105
- return ( collection . collectionName . indexOf ( this . _collectionPrefix ) == 0 ) ;
106
- } ) ;
107
- } ) ;
104
+ return storageAdapterAllCollections ( this )
105
+ . then ( collections => Promise . all ( collections . map ( collection => collection . drop ( ) ) ) ) ;
108
106
}
109
107
110
108
// Remove the column and all the data. For Relations, the _Join collection is handled
0 commit comments