Make parts of SchemasRouter use adaptiveCollection.

This commit is contained in:
Nikita Lutsenko
2016-03-01 20:24:36 -08:00
parent abde9484ce
commit 9538a7dab5
2 changed files with 22 additions and 19 deletions

View File

@@ -46,4 +46,8 @@ export default class MongoCollection {
count(query, { skip, limit, sort } = {}) { count(query, { skip, limit, sort } = {}) {
return this._mongoCollection.count(query, { skip, limit, sort }); return this._mongoCollection.count(query, { skip, limit, sort });
} }
drop() {
return this._mongoCollection.drop();
}
} }

View File

@@ -38,11 +38,10 @@ function mongoSchemaToSchemaAPIResponse(schema) {
} }
function getAllSchemas(req) { function getAllSchemas(req) {
return req.config.database.collection('_SCHEMA') return req.config.database.adaptiveCollection('_SCHEMA')
.then(coll => coll.find({}).toArray()) .then(collection => collection.find({}))
.then(schemas => ({response: { .then(schemas => schemas.map(mongoSchemaToSchemaAPIResponse))
results: schemas.map(mongoSchemaToSchemaAPIResponse) .then(schemas => ({ response: { results: schemas }}));
}}));
} }
function getOneSchema(req) { function getOneSchema(req) {
@@ -152,7 +151,7 @@ function deleteSchema(req) {
throw new Parse.Error(Parse.Error.INVALID_CLASS_NAME, Schema.invalidClassNameMessage(req.params.className)); throw new Parse.Error(Parse.Error.INVALID_CLASS_NAME, Schema.invalidClassNameMessage(req.params.className));
} }
return req.config.database.collection(req.params.className) return req.config.database.adaptiveCollection(req.params.className)
.then(collection => { .then(collection => {
return collection.count() return collection.count()
.then(count => { .then(count => {
@@ -161,6 +160,7 @@ function deleteSchema(req) {
} }
return collection.drop(); return collection.drop();
}) })
})
.then(() => { .then(() => {
// We've dropped the collection now, so delete the item from _SCHEMA // We've dropped the collection now, so delete the item from _SCHEMA
// and clear the _Join collections // and clear the _Join collections
@@ -174,7 +174,6 @@ function deleteSchema(req) {
return removeJoinTables(req.config.database, doc.value); return removeJoinTables(req.config.database, doc.value);
}); });
}) })
})
.then(() => { .then(() => {
// Success // Success
return { response: {} }; return { response: {} };