parse.com - Querying inside Parse.Cloud.beforeSave -
here trying
parse.cloud.beforesave("users", function(request, response) { parse.cloud.usemasterkey(); var user = request.object; var query = new parse.query(parse.installation); query.equalto("installationid", user.get("installationid")); query.find({ success: function(results) { if(results !== undefined ) { console.log("beforesave users:" + results + " user exists :" +user.get("installationid")); response.error(); } else{ console.log("beforesave users:" + results + " creating user :" +user.get("installationid")); response.success(); } }, error: function(error) { // on error, log , return empty array console.log("beforesave users error :" + error.message); } }); });
it works fine in result
i2014-06-30t01:51:02.578z] v99: before_save triggered users input: {"original":null,"update":{"installationid":"ef0317be-e634-4f64-a482-810c9839117c","username":"test","userphonenumber":"0123456789"}} result: validation failed
why validation failed there? if remove parse.cloud.usemasterkey();
validation error goes away function stops working.
can explain please? why validation failed error?
even if results not found , empty array, want successful results. problem trying understand how adding or removing parse.cloud.usemasterkey();
makes difference in case.
it makes code work why result: validation failed.
your logic in success
handler incorrect.
if no matches found, results
parameter empty array. should checking length of 0.
given you're expecting single result though, should switch using first()
instead, in case want check undefined
.
Comments
Post a Comment