I am updating some previously working cloud code to the new Parse Server. I have updated it with the new method of passing useMasterKey.
The query part appears to be working as the resultingStations array gets populated, but the delete is failing.
Parse.Cloud.afterDelete("Workout", function(request) {
query = new Parse.Query("WorkoutStation");
query.equalTo("workout", request.object);
query.find({
success: function(resultingStations) {
console.log('Found these to delete:' + resultingStations);
Parse.Object.destroyAll(resultingStations, {
success: function() {
console.log('Did successfully delete');
},
error: function(error) {
console.error("Error deleting related workout stations " + error.code + ": " + error.message);
}
}, { useMasterKey: true });
},
error: function(error) {
console.error("Error finding related workout stations " + error.code + ": " + error.message);
}
}, { useMasterKey: true });
});
If I look in the dashboard the objects in resultingStations are still there, and in the server log I get the error:
"Error deleting related workout stations 600: undefined"
600 doesn't seem to be a valid error code.
Looking at the Parse.Error definitions on my local Parse Server (\node_modules\parse\lib\node\ParseError.js), code 600 indicates an Aggregate error as below:
/**
* Error code indicating that there were multiple errors. Aggregate errors
* have an "errors" property, which is an array of error objects with more
* detail about each error that occurred.
* @property AGGREGATE_ERROR
* @static
* @final
*/
ParseError.AGGREGATE_ERROR = 600;
Which explains why error.message
is undefined. error.errors
should be an array of errors, which could give you some hints to what's going wrong.
As for the root cause, I have a feeling it might be to do with the use of useMasterKey. I migrated to using Promises quite a while ago, but if I remember correctly it should be something like this (for the destroyAll section):
Parse.Object.destroyAll(resultingStations, {
success: function() {
console.log('Did successfully delete');
},
error: function(error) {
console.error("Error deleting related workout stations " + error.code + ": " + error.message);
},
useMasterKey: true
});