Add new MongoSchemaCollection class that manages schemas for all collections.

This commit is contained in:
Nikita Lutsenko
2016-03-09 15:20:59 -08:00
parent 72362bc604
commit 2730398b92
3 changed files with 71 additions and 0 deletions

View File

@@ -1,9 +1,12 @@
import MongoCollection from './MongoCollection';
import MongoSchemaCollection from './MongoSchemaCollection';
let mongodb = require('mongodb');
let MongoClient = mongodb.MongoClient;
const MongoSchemaCollectionName = '_SCHEMA';
export class MongoStorageAdapter {
// Private
_uri: string;
@@ -38,6 +41,12 @@ export class MongoStorageAdapter {
.then(rawCollection => new MongoCollection(rawCollection));
}
schemaCollection(collectionPrefix: string) {
return this.connect()
.then(() => this.adaptiveCollection(collectionPrefix + MongoSchemaCollectionName))
.then(collection => new MongoSchemaCollection(collection));
}
collectionExists(name: string) {
return this.connect().then(() => {
return this.database.listCollections({ name: name }).toArray();