in effort prevent objects being created, set conditional in type of object's beforesave cloud function.
however, when 2 objects created simultaneously, conditional not work accordingly.
here code:
parse.cloud.beforesave("entry", function(request, response) { var thecontest = request.object.get("contest"); thecontest.fetch().then(function(contest){ if (contest.get("isfilled") == true) { response.error('this contest full.'); } else { response.success(); }); });
basically, don't want entry object created if contest full. however, if there 1 spot in contest remaining , 2 entries saved simultaneously, both added.
i know edge-case, legitimate concern.
parse using mongodb nosql database designed scalable , therefore provides limited synchronisation features. need here mutual exclusion unfortunately not supported on boolean
field. parse provides atomicity counters , array fields can use enforce control.
see http://blog.parse.com/announcements/new-atomic-operations-for-arrays/ , https://parse.com/docs/js/guide#objects-updating-objects
Comments
Post a Comment