Remove direct mongo access from Schema.spec.js.

This commit is contained in:
Nikita Lutsenko
2016-02-29 19:41:05 -08:00
parent 6893895aea
commit 2733c0924b
3 changed files with 36 additions and 19 deletions

View File

@@ -30,8 +30,12 @@ export class MongoStorageAdapter {
});
}
dropCollection(name: string) {
return this.connect.then(() => this.collection(name).then(collection => collection.drop()));
collectionExists(name: string) {
return this.connect().then(() => {
return this.database.listCollections({ name: name }).toArray();
}).then(collections => {
return collections.length > 0;
});
}
dropCollection(name: string) {

View File

@@ -38,6 +38,10 @@ DatabaseController.prototype.collection = function(className) {
return this.rawCollection(className);
};
DatabaseController.prototype.collectionExists = function(className) {
return this.adapter.collectionExists(this.collectionPrefix + className);
};
DatabaseController.prototype.rawCollection = function(className) {
return this.adapter.collection(this.collectionPrefix + className);
};