Parse server useMasterKey syntax

I am using a simple query to increment the stock of a product. The query works when the class level permissions are set to public read and write however I cannot work out how to get the query to use the master key so that the class can be restricted from client-side changes. How should this be done?

itemQuery.equalTo('productName', items[count]);
  success: function(object) {
    // Successfully retrieved the object.
    object.increment('stock', 1);;

1 answer

  • answered 2018-01-11 21:08 danh

    Set the class level permissions to restrict access as you see fit, then in cloud code you have two options: (1) user master key for the whole cloud function:

    itemQuery.equalTo('productName', items[count]);
    // and so on...

    Or (2) better, apply master key as an option for only the action that might be restricted:

    // etc, { useMasterKey: true });