Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse Cloud deleting objects from query

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.

like image 411
sailor Avatar asked May 20 '26 13:05

sailor


1 Answers

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.

like image 96
Fosco Avatar answered May 22 '26 03:05

Fosco



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!