Skip to content Skip to sidebar Skip to footer

Parse: Remove User And Its Related Records

I have Parse table with entities. User - default class Commets - class with pointer to _User entity. I need to delete user from entity User together with all its comments, located

Solution 1:

As eth3lbert pointed out in the comments, you should use an afterDelete hook that gets called after the User object has been deleted. You can kick off any other delete operations you want.

However, there is a little gotcha, the before* and after* methods get killed after 3 seconds of wall clock time which might lead to unwanted results depending on the amount of data that you need to delete.

The best solution for you is to setup a background job (they can run for up to 15 minutes), schedule it to run, lets say once every day, and do any cleanup work in that job.

You could create a simple table for that, that contains the objectIds of deleted users, whenever your afterDelete method gets called, you add the deleted users id into that table, your background job then queries that table on run and deletes the content that was associated with it.

Solution 2:

You can delete user easily from user request as below.

Parse.Cloud.define('deleteUser', async (req) => {
  const user = req.user;
  return user.destroy({ useMasterKey: true});
})

and add additional deleting logic related to User.

Post a Comment for "Parse: Remove User And Its Related Records"