I have duplication problem with parse server

20 Views Asked by At

I have a problem in parse server, for a specific class (table) I used beforeSave trigger, like this (for example...) :

Parse.Cloud.beforeSave("PostsReacts", async (request) => {
  var username = request.user.get("username");
  var post = request.object.get("post");
  var reactsQuery = new Parse.Query("PostsReacts").equalTo("post",post).equalTo("user",username);
  var reacts = await reactsQuery.find();
  if(reacts.length == 1)
  {
    throw "Already reacted on this post."
  }
});

The problem is when I handle a lot of requests at the same time...

I tried to destroy duplicated objects using afterSave trigger, but the problem still exist... Moreover, I cannot create unique index in mongodb because I need to prevent duplicated user in each post separately, not for all table...

0

There are 0 best solutions below