From 0dec1c80e23c731e767d02248c9d119db8cc6cbf Mon Sep 17 00:00:00 2001 From: Antonio Davi Macedo Coelho de Castro Date: Wed, 22 Apr 2020 09:04:07 -0700 Subject: [PATCH] Fix #6586 (#6605) --- .../Storage/Mongo/MongoSchemaCollection.js | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/Adapters/Storage/Mongo/MongoSchemaCollection.js b/src/Adapters/Storage/Mongo/MongoSchemaCollection.js index 46ba3e81..d824787c 100644 --- a/src/Adapters/Storage/Mongo/MongoSchemaCollection.js +++ b/src/Adapters/Storage/Mongo/MongoSchemaCollection.js @@ -42,7 +42,7 @@ function mongoFieldToParseSchemaField(type) { const nonFieldSchemaKeys = ['_id', '_metadata', '_client_permissions']; function mongoSchemaFieldsToParseSchemaFields(schema) { var fieldNames = Object.keys(schema).filter( - key => nonFieldSchemaKeys.indexOf(key) === -1 + (key) => nonFieldSchemaKeys.indexOf(key) === -1 ); var response = fieldNames.reduce((obj, fieldName) => { obj[fieldName] = mongoFieldToParseSchemaField(schema[fieldName]); @@ -110,7 +110,7 @@ function mongoSchemaToParseSchema(mongoSchema) { function _mongoSchemaQueryFromNameQuery(name: string, query) { const object = { _id: name }; if (query) { - Object.keys(query).forEach(key => { + Object.keys(query).forEach((key) => { object[key] = query[key]; }); } @@ -158,13 +158,13 @@ class MongoSchemaCollection { _fetchAllSchemasFrom_SCHEMA() { return this._collection ._rawFind({}) - .then(schemas => schemas.map(mongoSchemaToParseSchema)); + .then((schemas) => schemas.map(mongoSchemaToParseSchema)); } _fetchOneSchemaFrom_SCHEMA(name: string) { return this._collection ._rawFind(_mongoSchemaQueryFromNameQuery(name), { limit: 1 }) - .then(results => { + .then((results) => { if (results.length === 1) { return mongoSchemaToParseSchema(results[0]); } else { @@ -175,17 +175,16 @@ class MongoSchemaCollection { // Atomically find and delete an object based on query. findAndDeleteSchema(name: string) { - return this._collection._mongoCollection.findAndRemove( - _mongoSchemaQueryFromNameQuery(name), - [] + return this._collection._mongoCollection.findOneAndDelete( + _mongoSchemaQueryFromNameQuery(name) ); } insertSchema(schema: any) { return this._collection .insertOne(schema) - .then(result => mongoSchemaToParseSchema(result.ops[0])) - .catch(error => { + .then((result) => mongoSchemaToParseSchema(result.ops[0])) + .catch((error) => { if (error.code === 11000) { //Mongo's duplicate key error throw new Parse.Error( @@ -226,7 +225,7 @@ class MongoSchemaCollection { addFieldIfNotExists(className: string, fieldName: string, fieldType: string) { return this._fetchOneSchemaFrom_SCHEMA(className) .then( - schema => { + (schema) => { // If a field with this name already exists, it will be handled elsewhere. if (schema.fields[fieldName] != undefined) { return; @@ -236,7 +235,7 @@ class MongoSchemaCollection { // Make sure there are not other geopoint fields if ( Object.keys(schema.fields).some( - existingField => + (existingField) => schema.fields[existingField].type === 'GeoPoint' ) ) { @@ -248,7 +247,7 @@ class MongoSchemaCollection { } return; }, - error => { + (error) => { // If error is undefined, the schema doesn't exist, and we can create the schema with the field. // If some other error, reject with it. if (error === undefined) {