diff --git a/src/Adapters/Storage/Mongo/MongoStorageAdapter.js b/src/Adapters/Storage/Mongo/MongoStorageAdapter.js index 66342e0b9e..da967cb49a 100644 --- a/src/Adapters/Storage/Mongo/MongoStorageAdapter.js +++ b/src/Adapters/Storage/Mongo/MongoStorageAdapter.js @@ -70,8 +70,15 @@ export class MongoStorageAdapter { }); } - dropCollection(name: string) { - return this.collection(this._collectionPrefix + name).then(collection => collection.drop()); + dropCollection(className: string) { + return this.collection(this._collectionPrefix + className).then(collection => collection.drop()) + .catch(error => { + // 'ns not found' means collection was already gone. Ignore deletion attempt. + if (error.message == 'ns not found') { + return Promise.resolve(); + } + return Promise.reject(error); + }); } // Used for testing only right now. diff --git a/src/Controllers/DatabaseController.js b/src/Controllers/DatabaseController.js index d0e92acb5b..84b942466c 100644 --- a/src/Controllers/DatabaseController.js +++ b/src/Controllers/DatabaseController.js @@ -44,10 +44,6 @@ DatabaseController.prototype.collectionExists = function(className) { return this.adapter.collectionExists(className); }; -DatabaseController.prototype.dropCollection = function(className) { - return this.adapter.dropCollection(className); -}; - DatabaseController.prototype.validateClassName = function(className) { if (this.skipValidation) { return Promise.resolve(); diff --git a/src/Routers/SchemasRouter.js b/src/Routers/SchemasRouter.js index 574aeb09d4..1f0bde9ede 100644 --- a/src/Routers/SchemasRouter.js +++ b/src/Routers/SchemasRouter.js @@ -93,7 +93,7 @@ var removeJoinTables = (database, mongoSchema) => { .filter(field => mongoSchema[field].startsWith('relation<')) .map(field => { let collectionName = `_Join:${field}:${mongoSchema._id}`; - return database.dropCollection(collectionName); + return database.adapter.dropCollection(collectionName); }) ); }; @@ -117,17 +117,7 @@ function deleteSchema(req) { return removeJoinTables(req.config.database, document); }); }) - .then(() => { - // Success - return { response: {} }; - }, error => { - if (error.message == 'ns not found') { - // If they try to delete a non-existent class, that's fine, just let them. - return { response: {} }; - } - - return Promise.reject(error); - }); + .then(() => ({ response: {} })); } export class SchemasRouter extends PromiseRouter { diff --git a/src/Schema.js b/src/Schema.js index 880a224f86..4bbad9dfd7 100644 --- a/src/Schema.js +++ b/src/Schema.js @@ -525,15 +525,7 @@ class Schema { if (this.data[className][fieldName].type == 'Relation') { //For relations, drop the _Join table return database.adapter.deleteFields(className, [fieldName], []) - .then(() => database.dropCollection(`_Join:${fieldName}:${className}`)) - .catch(error => { - // 'ns not found' means collection was already gone. Ignore deletion attempt. - // TODO: 'ns not found' is a mongo implementation detail. Move it into mongo adapter. - if (error.message == 'ns not found') { - return Promise.resolve(); - } - return Promise.reject(error); - }); + .then(() => database.adapter.dropCollection(`_Join:${fieldName}:${className}`)); } const fieldNames = [fieldName];