我正在将一些以前工作的云代码更新到新的解析服务器。我已经使用传递 useMasterKey 的新方法更新了它。
在填充结果工作站数组时,查询部分似乎正在工作,但删除失败。
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 });
});
如果我在仪表板中查看结果站中的对象仍然存在,并且在服务器日志中出现错误:
"删除相关锻炼站 600 时出错:未定义"
600 似乎不是有效的错误代码。
此处的错误代码列表
查看我的本地解析服务器 (ode_modules\parse\libode\ParseError.js) 上的 Parse.Error 定义,代码 600 指示聚合错误,如下所示:
/**
* 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;
这就解释了为什么error.message
是未定义的。 error.errors
应该是一系列错误,这可以为您提供一些关于出错的提示。
至于根本原因,我有一种感觉,这可能与使用useMasterKey有关。很久以前我迁移到使用 Promises,但如果我没记错的话,它应该是这样的(对于 destroyAll 部分):
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
});