I can't figure out how to delete all the objects retrieved via a Parse Cloud job query. When I run this job, nothing from the database has been deleted.
Here's the troublesome snippet:
query.find({
success: function(posts) {
Parse.Object.destroyAll(posts);
status.success("success");
},
error: function(error) {
status.error("Error finding posts " + error.code + ": " + error.message);
},
});
I have also tried using a for-loop and calling .destroy() on each post, which doesn't work. I also tested changing attributes on each post using .set(), which also didn't work. However, I am easily able to use .get() to retrieve attributes. Where am I going wrong?
UPDATE: It was an authentication error.
useMasterKey: true
Adding this to destroyAll() as an option made it work.
Try waiting for the destroy to complete before continuing.. something like:
query.find({
success: function(posts) {
Parse.Object.destroyAll(posts).then(function() {
status.success("success");
});
},
error: function(error) {
status.error("Error finding posts " + error.code + ": " + error.message);
},
});
Asynchronous JavaScript trips everyone up.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With