Within "afterSave" method in Parse, I want to increment a field in a Parse Object. I get the object and increment in the following way:
Parse.Cloud.afterSave("Activity", function(request) {
if(request.object.get("type") == "joinedGame") {
var aGameObject = request.object.get("toGameR");
var gameRQuery = new Parse.Query("GameR");
gameRQuery.get(aGameObject, {
success: function (obj) {
obj.Increment("numberOfPlayers");
obj.save();
},
error: function(error) {
console.log("Failed: " +error.message);
}
});
}
This code increments "numberOfPlayers" field as many times as the "afterSave" function gets called and the first "if" statement holds true. "obj" is also saved. Incremented "numberOfPlayers" field is shown in the Parse DB. However, Parse log shows the following error:
Result: TypeError: Object [object Object] has no method 'Increment'