javascript - Parse Cloud Code - Only Retrieve Certain Columns Before Sending Response. -
i have cloud code retrieve users have relation current user. have first find current user query "friends" column hence relational query step.
the line response.success(results)
returns attributes of of current user's friends. want few of columns belong these friends, not every single thing saved when signing up.
parse.cloud.define("getfriends", function(request, response) { var userid = request.params.userkey; var query = new parse.query(parse.user); query.ascending("updatedat"); query.get(userid, { success: function(foundcurrentuser) { var currentuser = foundcurrentuser; var relation = currentuser.relation("friends"); var getrelationquery = relation.query(); getrelationquery.find().then(function(results) { response.success(results); }); }, error: function(error) { response.error(error); } }); });
i using swift to use response, not sure if need tweak swift code provide anyway.
func loadcarpoolersfromparse(success:(object:anyobject)->(),failure:(error:nserror)->()) { let params = nsmutabledictionary() params.setobject(pfuser.currentuser()!.objectid!, forkey: "userkey") pfcloud.callfunctioninbackground("getcarpoolers", withparameters: params [nsobject : anyobject], block: { (response:anyobject?, error: nserror?) -> void in if error == nil { success(object: response!) } else{ failure(error:error!) } }) } }
you can using select
method of parse.query
, make following changes in cloud code
parse.cloud.define("getfriends", function(request, response) { var userid = request.params.userkey; var query = new parse.query(parse.user); query.ascending("updatedat"); query.select("name","phone"); // replace required fields
Comments
Post a Comment