Schema format cleanup
This commit is contained in:
@@ -115,9 +115,20 @@ class MongoSchemaCollection {
|
||||
});
|
||||
}
|
||||
|
||||
// Add a collection. Currently the input is in mongo format, but that will change to Parse format in a
|
||||
// later PR. Returns a promise that is expected to resolve with the newly created schema, in Parse format.
|
||||
// If the class already exists, returns a promise that rejects with undefined as the reason. If the collection
|
||||
// can't be added for a reason other than it already existing, requirements for rejection reason are TBD.
|
||||
addSchema(name: string, fields) {
|
||||
let mongoObject = _mongoSchemaObjectFromNameFields(name, fields);
|
||||
return this._collection.insertOne(mongoObject);
|
||||
return this._collection.insertOne(mongoObject)
|
||||
.then(result => mongoSchemaToParseSchema(result.ops[0]))
|
||||
.catch(error => {
|
||||
if (error.code === 11000) { //Mongo's duplicate key error
|
||||
return Promise.reject();
|
||||
}
|
||||
return Promise.reject(error);
|
||||
});
|
||||
}
|
||||
|
||||
updateSchema(name: string, update) {
|
||||
|
||||
Reference in New Issue
Block a user