@@ -50,37 +50,38 @@ export class MongoStorageAdapter {
5050
5151 adaptiveCollection ( name : string ) {
5252 return this . connect ( )
53- . then ( ( ) => this . database . collection ( name ) )
53+ . then ( ( ) => this . database . collection ( this . _collectionPrefix + name ) )
5454 . then ( rawCollection => new MongoCollection ( rawCollection ) ) ;
5555 }
5656
57- schemaCollection ( collectionPrefix : string ) {
57+ schemaCollection ( ) {
5858 return this . connect ( )
59- . then ( ( ) => this . adaptiveCollection ( collectionPrefix + MongoSchemaCollectionName ) )
59+ . then ( ( ) => this . adaptiveCollection ( this . _collectionPrefix + MongoSchemaCollectionName ) )
6060 . then ( collection => new MongoSchemaCollection ( collection ) ) ;
6161 }
6262
6363 collectionExists ( name : string ) {
6464 return this . connect ( ) . then ( ( ) => {
65- return this . database . listCollections ( { name : name } ) . toArray ( ) ;
65+ return this . database . listCollections ( { name : this . _collectionPrefix + name } ) . toArray ( ) ;
6666 } ) . then ( collections => {
6767 return collections . length > 0 ;
6868 } ) ;
6969 }
7070
7171 dropCollection ( name : string ) {
72- return this . collection ( name ) . then ( collection => collection . drop ( ) ) ;
72+ return this . collection ( this . _collectionPrefix + name ) . then ( collection => collection . drop ( ) ) ;
7373 }
74+
7475 // Used for testing only right now.
75- collectionsContaining ( match : string ) {
76+ allCollections ( ) {
7677 return this . connect ( ) . then ( ( ) => {
7778 return this . database . collections ( ) ;
7879 } ) . then ( collections => {
7980 return collections . filter ( collection => {
8081 if ( collection . namespace . match ( / \. s y s t e m \. / ) ) {
8182 return false ;
8283 }
83- return ( collection . collectionName . indexOf ( match ) == 0 ) ;
84+ return ( collection . collectionName . indexOf ( this . _collectionPrefix ) == 0 ) ;
8485 } ) ;
8586 } ) ;
8687 }
@@ -106,12 +107,12 @@ export class MongoStorageAdapter {
106107
107108 // Returns a Promise.
108109
109- // This function currently accepts the collectionPrefix and adaptive collection as a paramater because it isn't
110+ // This function currently accepts the adaptive collection as a paramater because it isn't
110111 // actually capable of determining the location of it's own _SCHEMA collection without having
111112 // the collectionPrefix. Also, Schemas.js, the caller of this function, only stores the collection
112113 // itself, and not the prefix. Eventually Parse Server won't care what a SchemaCollection is and
113114 // will just tell the DB adapter to do things and it will do them.
114- deleteFields ( className : string , fieldNames , pointerFieldNames , collectionPrefix , adaptiveCollection ) {
115+ deleteFields ( className : string , fieldNames , pointerFieldNames , adaptiveCollection ) {
115116 const nonPointerFieldNames = _ . difference ( fieldNames , pointerFieldNames ) ;
116117 const mongoFormatNames = nonPointerFieldNames . concat ( pointerFieldNames . map ( name => `_p_${ name } ` ) ) ;
117118 const collectionUpdate = { '$unset' : { } } ;
@@ -125,9 +126,7 @@ export class MongoStorageAdapter {
125126 } ) ;
126127
127128 return adaptiveCollection . updateMany ( { } , collectionUpdate )
128- . then ( updateResult => {
129- return this . schemaCollection ( collectionPrefix )
130- } )
129+ . then ( updateResult => this . schemaCollection ( ) )
131130 . then ( schemaCollection => schemaCollection . updateSchema ( className , schemaUpdate ) ) ;
132131 }
133132}
0 commit comments