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 } = {}) {
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) {
return req.config.database.collection('_SCHEMA')
.then(coll => coll.find({}).toArray())
.then(schemas => ({response: {
results: schemas.map(mongoSchemaToSchemaAPIResponse)
}}));
return req.config.database.adaptiveCollection('_SCHEMA')
.then(collection => collection.find({}))
.then(schemas => schemas.map(mongoSchemaToSchemaAPIResponse))
.then(schemas => ({ response: { results: schemas }}));
}
function getOneSchema(req) {
@@ -152,7 +151,7 @@ function deleteSchema(req) {
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 => {
return collection.count()
.then(count => {
@@ -161,6 +160,7 @@ function deleteSchema(req) {
}
return collection.drop();
})
})
.then(() => {
// We've dropped the collection now, so delete the item from _SCHEMA
// and clear the _Join collections
@@ -174,7 +174,6 @@ function deleteSchema(req) {
return removeJoinTables(req.config.database, doc.value);
});
})
})
.then(() => {
// Success
return { response: {} };