如何从表格中删除最后一天的记录
Parse.Cloud.job("deleteOldEntries", function(request, status) {
var GameScore = Parse.Object.extend("GameScore");
var query = new Parse.Query(GameScore);
var day = new Date();
day.setDate(day.getDate()-1);
query.lessThan("createdAt", day);
query.find({
success:function(results) {
console.log(results);
for (var i = 0, len = results.length; i < len; i++) {
var result = results[i];
result.destroy({});
console.log("Destroy: "+result);
}
status.success("Delete successfully.");
},
error: function(error) {
status.error("Uh oh, something went wrong.");
console.log("Failed!");
}
})
});
我正在使用此代码删除最后一天的记录,它已成功部署到服务器。之后我成功安排了作业,但记录不删除。
任何帮助表示赞赏。
Best Answer-推荐答案 strong>
Parse.Cloud.job("deleteMessages", function(request, status) {
Parse.Cloud.useMasterKey();
var ts = Math.round(new Date().getTime() / 1000);
var tsYesterday = ts - (24 * 3600);
var dateYesterday = new Date(tsYesterday*1000);
var query = new Parse.Query("Your Object Class");
query.lessThan("createdAt", dateYesterday);
query.find({
success: function(result) {
for(var i=0; i<result.length; i++) {
result[i].destroy({
success: function(object) {
status.success("Delete job completed");
alert('Delete Successful');
},
error: function(object, error) {
status.error("Delete error :" + error);
alert('Delete failed');
}
});
}
status.success("Delete job completed");
},
error: function(error) {
status.error("Error in delete query error: " + error);
alert('Error in delete query');
}
});
});
关于ios - 创建用于删除最后一天记录的后台作业,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/27313958/
|