Hi, I'm trying to add pagination in the GetTeamRequest method, I've two questions about it.
1.- When I add extra params to the team request I get an error. (Unrecognized field \"limit\" (Class com.gamesparks.messages.requests.GetTeamRequest), not marked as ignorable). Where or How Can I add the ignorable flag?
2.- How Can I change the default query in the CloudCode (Requests->GetTeamRequests) to permit pagination when limit or offset are available.
Thanks a lot.
Best Answer
C
Customer Support
said
about 7 years ago
Hey Oscar,
Sorry, im not sure i understand your problem, but allow me to get it straight in head; You are trying to send back multiple responses, or multiple batches of script-data when there is more than a certain amount of docs in a GetTeamRequest? Is that right?
[1] - I believe, if i am correct, that you tried to add a limit to the GetTeamRequest in cloud-code, and the error you are getting is because there is no limit in that request. You can check out a more specific api here, that shows exactly what it will take.
[2] - im unsure what you mean by default-query, but we have a piece of code that might allow you to preform pagination on your GetTeamRequest the way i understand it at least.
var progressCollection = Spark.runtimeCollection("teams"); // the name within parentheses can be any collection name
//Get the value that was passed in for PATH
var inputPath = Spark.data.PATH; // this specifies the exact field, ie - name or whatever. it's passed in in the TH or in client side code
var teamID = Spark.data.TEAM; // the team entry to query
var newPartialResult = {}; // we'll dump the new results into this
for (var i = 0; i < progressCollection.length; i++){ if(inputPath.length === 0){
//No input path, we want the whole document
var resultDocument = progressCollection[i].find({"id" : teamID});
//Put the results into the response.
Spark.setScriptData("data", resultDocument);
} else {
//The query object for the aggregation
var matchObject = {"$match" : {"id": teamID}};
//We want to use the last part of the path as the key in the returned data
//We don't have to do it, but the result will make more sense
var pathArray = inputPath.split(".");
var lastPathString = pathArray[pathArray.length - 1];
//Now we build up the object the spacified the fields we want to return
var projectData = {"_id":0 };
//Using [] notation so we can use a variable as a JSON attribute name
projectData[lastPathString] = "$"+inputPath;
var projectObject = {"$project" : projectData};
//Run the aggregation
var partialResult = progressCollection[i].aggregate(matchObject, projectObject);
newPartialResult[i] = partialResult;
}
}
Hope that helps, Sean
1 Comment
Customer Support
said
about 7 years ago
Answer
Hey Oscar,
Sorry, im not sure i understand your problem, but allow me to get it straight in head; You are trying to send back multiple responses, or multiple batches of script-data when there is more than a certain amount of docs in a GetTeamRequest? Is that right?
[1] - I believe, if i am correct, that you tried to add a limit to the GetTeamRequest in cloud-code, and the error you are getting is because there is no limit in that request. You can check out a more specific api here, that shows exactly what it will take.
[2] - im unsure what you mean by default-query, but we have a piece of code that might allow you to preform pagination on your GetTeamRequest the way i understand it at least.
var progressCollection = Spark.runtimeCollection("teams"); // the name within parentheses can be any collection name
//Get the value that was passed in for PATH
var inputPath = Spark.data.PATH; // this specifies the exact field, ie - name or whatever. it's passed in in the TH or in client side code
var teamID = Spark.data.TEAM; // the team entry to query
var newPartialResult = {}; // we'll dump the new results into this
for (var i = 0; i < progressCollection.length; i++){ if(inputPath.length === 0){
//No input path, we want the whole document
var resultDocument = progressCollection[i].find({"id" : teamID});
//Put the results into the response.
Spark.setScriptData("data", resultDocument);
} else {
//The query object for the aggregation
var matchObject = {"$match" : {"id": teamID}};
//We want to use the last part of the path as the key in the returned data
//We don't have to do it, but the result will make more sense
var pathArray = inputPath.split(".");
var lastPathString = pathArray[pathArray.length - 1];
//Now we build up the object the spacified the fields we want to return
var projectData = {"_id":0 };
//Using [] notation so we can use a variable as a JSON attribute name
projectData[lastPathString] = "$"+inputPath;
var projectObject = {"$project" : projectData};
//Run the aggregation
var partialResult = progressCollection[i].aggregate(matchObject, projectObject);
newPartialResult[i] = partialResult;
}
}
Oscar Alarcon
Hi, I'm trying to add pagination in the GetTeamRequest method, I've two questions about it.
1.- When I add extra params to the team request I get an error. (Unrecognized field \"limit\" (Class com.gamesparks.messages.requests.GetTeamRequest), not marked as ignorable). Where or How Can I add the ignorable flag?
2.- How Can I change the default query in the CloudCode (Requests->GetTeamRequests) to permit pagination when limit or offset are available.
Thanks a lot.
Sorry, im not sure i understand your problem, but allow me to get it straight in head; You are trying to send back multiple responses, or multiple batches of script-data when there is more than a certain amount of docs in a GetTeamRequest? Is that right?
[1] - I believe, if i am correct, that you tried to add a limit to the GetTeamRequest in cloud-code, and the error you are getting is because there is no limit in that request. You can check out a more specific api here, that shows exactly what it will take.
[2] - im unsure what you mean by default-query, but we have a piece of code that might allow you to preform pagination on your GetTeamRequest the way i understand it at least.
Hope that helps,
Sean
Customer Support
Sorry, im not sure i understand your problem, but allow me to get it straight in head; You are trying to send back multiple responses, or multiple batches of script-data when there is more than a certain amount of docs in a GetTeamRequest? Is that right?
[1] - I believe, if i am correct, that you tried to add a limit to the GetTeamRequest in cloud-code, and the error you are getting is because there is no limit in that request. You can check out a more specific api here, that shows exactly what it will take.
[2] - im unsure what you mean by default-query, but we have a piece of code that might allow you to preform pagination on your GetTeamRequest the way i understand it at least.
Hope that helps,
Sean
-
Documentation Notes
-
Design issues with user events
-
Using NoSQL
-
Runtime Collections vs Metadata Collections
-
Anonymous authentication from browser app
-
Modules
-
Movement With Unity
-
Problem with url parameters for downloadables
-
Querying NoSql GameSparks database
-
Challenge accesType
See all 2487 topics