Skip to content

Commit a622a18

Browse files
committed
Make parts of SchemasRouter use adaptiveCollection.
1 parent a507f3f commit a622a18

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

src/Adapters/Storage/Mongo/MongoCollection.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,8 @@ export default class MongoCollection {
4242
count(query, { skip, limit, sort } = {}) {
4343
return this._mongoCollection.count(query, { skip, limit, sort });
4444
}
45+
46+
drop() {
47+
return this._mongoCollection.drop();
48+
}
4549
}

src/Routers/SchemasRouter.js

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,10 @@ function mongoSchemaToSchemaAPIResponse(schema) {
3838
}
3939

4040
function getAllSchemas(req) {
41-
return req.config.database.collection('_SCHEMA')
42-
.then(coll => coll.find({}).toArray())
43-
.then(schemas => ({response: {
44-
results: schemas.map(mongoSchemaToSchemaAPIResponse)
45-
}}));
41+
return req.config.database.adaptiveCollection('_SCHEMA')
42+
.then(collection => collection.find({}))
43+
.then(schemas => schemas.map(mongoSchemaToSchemaAPIResponse))
44+
.then(schemas => ({ response: { results: schemas }}));
4645
}
4746

4847
function getOneSchema(req) {
@@ -152,7 +151,7 @@ function deleteSchema(req) {
152151
throw new Parse.Error(Parse.Error.INVALID_CLASS_NAME, Schema.invalidClassNameMessage(req.params.className));
153152
}
154153

155-
return req.config.database.collection(req.params.className)
154+
return req.config.database.adaptiveCollection(req.params.className)
156155
.then(collection => {
157156
return collection.count()
158157
.then(count => {
@@ -161,19 +160,19 @@ function deleteSchema(req) {
161160
}
162161
return collection.drop();
163162
})
164-
.then(() => {
165-
// We've dropped the collection now, so delete the item from _SCHEMA
166-
// and clear the _Join collections
167-
return req.config.database.collection('_SCHEMA')
168-
.then(coll => coll.findAndRemove({_id: req.params.className}, []))
169-
.then(doc => {
170-
if (doc.value === null) {
171-
//tried to delete non-existent class
172-
return Promise.resolve();
173-
}
174-
return removeJoinTables(req.config.database, doc.value);
175-
});
176-
})
163+
})
164+
.then(() => {
165+
// We've dropped the collection now, so delete the item from _SCHEMA
166+
// and clear the _Join collections
167+
return req.config.database.collection('_SCHEMA')
168+
.then(coll => coll.findAndRemove({_id: req.params.className}, []))
169+
.then(doc => {
170+
if (doc.value === null) {
171+
//tried to delete non-existent class
172+
return Promise.resolve();
173+
}
174+
return removeJoinTables(req.config.database, doc.value);
175+
});
177176
})
178177
.then(() => {
179178
// Success

0 commit comments

Comments
 (0)