Parse javascript deleteAll() 只删除 20 个对象,即使我的限制是 1000 个?
Parse javascript deleteAll() only deletes 20 objects even though my limit is 1000?
我试图从服务器上删除超过 1 天的图像,但出于某种原因,即使我将限制设置为 1000,它也只删除了 20 张图像。
代码如下:
Parse.Cloud.job("deleteImages", function(request, status) {
Parse.Cloud.useMasterKey();
//Get yesterday
var ts = Math.round(new Date().getTime() / 1000);
var tsYesterday = ts - (24 * 3600);
var dateYesterday = new Date(tsYesterday*1000);
//Query with limit 1000
var query = new Parse.Query("image");
query.lessThan("createdAt", dateYesterday);
query.limit(1000);
query.find({
success: function(result) {
Parse.Object.destroyAll(result, {
success: function() {
status.success("Delete job completed");
console.log("Success");
},
error: function(error) {
if (error.code == Parse.Error.AGGREGATE_ERROR) {
for (var i = 0; i < error.errors.length; i++) {
console.log("Couldn't delete " + error.errors[i].object.id +
"due to " + error.errors[i].message);
status.error("Delete error :" + error);
}
} else {
status.error("Delete error :" + error);
console.log("Delete aborted because of " + error.message);
}
},
});
status.success("Delete job completed");
},
error: function(error) {
status.error("Error in delete query error: " + error);
alert('Error in delete query');
}
});
});
如有任何帮助,我们将不胜感激!
谢谢
对于遇到同样问题的其他人来说,这个解决方案真的很奇怪,我不明白它为什么有效。但是,通过从代码中完全删除 status.success() 似乎可以完成工作。我收到一条错误消息“Failed with: success/error was not called”,但它仍然删除了 1000 张图像。
Parse.Cloud.job("deleteImages", function(request, status) {
Parse.Cloud.useMasterKey();
//Get yesterday
var ts = Math.round(new Date().getTime() / 1000);
var tsYesterday = ts - (24 * 3600);
var dateYesterday = new Date(tsYesterday*1000);
//Query with limit 1000
var query = new Parse.Query("image");
query.lessThan("createdAt", dateYesterday);
query.limit(1000);
query.find({
success: function(result) {
Parse.Object.destroyAll(result, {
success: function() {
console.log("Success");
},
error: function(error) {
if (error.code == Parse.Error.AGGREGATE_ERROR) {
for (var i = 0; i < error.errors.length; i++) {
console.log("Couldn't delete " + error.errors[i].object.id +
"due to " + error.errors[i].message);
}
} else {
console.log("Delete aborted because of " + error.message);
}
}
});
},
error: function(error) {
status.error("Error in delete query error: " + error);
}
});
});
我发现 post 与您的问题完全相关。
https://parse.com/questions/background-job-remove-all-objects-for-user
"Calling status.success() or status.error() at any point will terminate the job."
我试图从服务器上删除超过 1 天的图像,但出于某种原因,即使我将限制设置为 1000,它也只删除了 20 张图像。
代码如下:
Parse.Cloud.job("deleteImages", function(request, status) {
Parse.Cloud.useMasterKey();
//Get yesterday
var ts = Math.round(new Date().getTime() / 1000);
var tsYesterday = ts - (24 * 3600);
var dateYesterday = new Date(tsYesterday*1000);
//Query with limit 1000
var query = new Parse.Query("image");
query.lessThan("createdAt", dateYesterday);
query.limit(1000);
query.find({
success: function(result) {
Parse.Object.destroyAll(result, {
success: function() {
status.success("Delete job completed");
console.log("Success");
},
error: function(error) {
if (error.code == Parse.Error.AGGREGATE_ERROR) {
for (var i = 0; i < error.errors.length; i++) {
console.log("Couldn't delete " + error.errors[i].object.id +
"due to " + error.errors[i].message);
status.error("Delete error :" + error);
}
} else {
status.error("Delete error :" + error);
console.log("Delete aborted because of " + error.message);
}
},
});
status.success("Delete job completed");
},
error: function(error) {
status.error("Error in delete query error: " + error);
alert('Error in delete query');
}
});
});
如有任何帮助,我们将不胜感激! 谢谢
对于遇到同样问题的其他人来说,这个解决方案真的很奇怪,我不明白它为什么有效。但是,通过从代码中完全删除 status.success() 似乎可以完成工作。我收到一条错误消息“Failed with: success/error was not called”,但它仍然删除了 1000 张图像。
Parse.Cloud.job("deleteImages", function(request, status) {
Parse.Cloud.useMasterKey();
//Get yesterday
var ts = Math.round(new Date().getTime() / 1000);
var tsYesterday = ts - (24 * 3600);
var dateYesterday = new Date(tsYesterday*1000);
//Query with limit 1000
var query = new Parse.Query("image");
query.lessThan("createdAt", dateYesterday);
query.limit(1000);
query.find({
success: function(result) {
Parse.Object.destroyAll(result, {
success: function() {
console.log("Success");
},
error: function(error) {
if (error.code == Parse.Error.AGGREGATE_ERROR) {
for (var i = 0; i < error.errors.length; i++) {
console.log("Couldn't delete " + error.errors[i].object.id +
"due to " + error.errors[i].message);
}
} else {
console.log("Delete aborted because of " + error.message);
}
}
});
},
error: function(error) {
status.error("Error in delete query error: " + error);
}
});
});
我发现 post 与您的问题完全相关。
https://parse.com/questions/background-job-remove-all-objects-for-user
"Calling status.success() or status.error() at any point will terminate the job."