I see in code examples how to return a query result (findOne) or many results (find). But how do I take two queries and combine them into one result?
var numLimit = Spark.getData().NumLimit; // get the limit from the client
var rand = Math.random();
var myData = Spark.runtimeCollection("myData"); // get the collection data
var resultsGt = myData .find({
"random": { $gte : rand }
}).limit(numLimit).sort({"random":1}); // search the collection data for a random entry greater than or equal to the random number
var resultsLt = myData.find({
"random": { $lte : rand }
}).limit(numLimit).sort({"random":-1}); // search the collection data for a random entry less than or equal to the random number
var resultCombined = // How do I combine resultsLt and resultsGt?
Spark.setScriptData("results_Data", resultCombined);
I suppose I could just call Spark.setScriptData once for each result.
Jason Reinsvold
I see in code examples how to return a query result (findOne) or many results (find). But how do I take two queries and combine them into one result?
I suppose I could just call Spark.setScriptData once for each result.
Would this be the recommended approach?
You could combine these into an array and send that array back in the response script-data. Does that work for you?
var results = [];
results.push(resultsGt);
results.push(resultsLt);
Spark.setScriptData("results_Data", results);
Let me know if this works.
Sean
Customer Support
You could combine these into an array and send that array back in the response script-data. Does that work for you?
var results = [];
results.push(resultsGt);
results.push(resultsLt);
Spark.setScriptData("results_Data", results);
Let me know if this works.
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