I'm trying to figure out how to use the like operator in a collection and the following works to find any levels that contain "Aw" in them:
var Levels = Spark.runtimeCollection('levels').find({"LevelName" : /Aw/});
However, how do I do this while passing in a variable? If I change it to
var Levels = Spark.runtimeCollection('levels').find({"LevelName" : '/'+ 'Aw' + '/'});
or
var Levels = Spark.runtimeCollection('levels').find({"LevelName" : VariableLevelName});
it doesn't work.
Thanks
Andy
Best Answer
C
Customer Support
said
over 4 years ago
Hi Andy,
If you pass this in as a string variable you can convert it to a Regular Expression. For example if you use the following it should work.
//create an event with a string attribute called "value", the string is what you want to search for
//here myValue would = "Aw"
var myValue = Spark.getData().value;
//convert it to a RegExp
var re = new RegExp(myValue); //re = /Aw/
//then use it in the search
var Levels = Spark.runtimeCollection('levels').find({"LevelName" : re});
Try that out and let me know how you get on, if you have any other question just let me know.
If you pass this in as a string variable you can convert it to a Regular Expression. For example if you use the following it should work.
//create an event with a string attribute called "value", the string is what you want to search for
//here myValue would = "Aw"
var myValue = Spark.getData().value;
//convert it to a RegExp
var re = new RegExp(myValue); //re = /Aw/
//then use it in the search
var Levels = Spark.runtimeCollection('levels').find({"LevelName" : re});
Try that out and let me know how you get on, if you have any other question just let me know.
Andy Sattler
Hello,
I'm trying to figure out how to use the like operator in a collection and the following works to find any levels that contain "Aw" in them:
var Levels = Spark.runtimeCollection('levels').find({"LevelName" : /Aw/});
However, how do I do this while passing in a variable? If I change it to
var Levels = Spark.runtimeCollection('levels').find({"LevelName" : '/'+ 'Aw' + '/'});
or
var Levels = Spark.runtimeCollection('levels').find({"LevelName" : VariableLevelName});
it doesn't work.
Thanks
Andy
Hi Andy,
If you pass this in as a string variable you can convert it to a Regular Expression. For example if you use the following it should work.
Try that out and let me know how you get on, if you have any other question just let me know.
Thanks,
Liam
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstCustomer Support
Hi Andy,
If you pass this in as a string variable you can convert it to a Regular Expression. For example if you use the following it should work.
Try that out and let me know how you get on, if you have any other question just let me know.
Thanks,
Liam
Andy Sattler
Awesome - that did it. Thank you.
-
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 2485 topics