Hello everoye, it's a very simple question, how do i get the lenght from an array that i got from a runtime collection in cloud code?
var EXAMPLE = Spark.runtimeCollection("RuntimeCollection").findOne({"_id": Spark.getPlayer().getPlayerId()},{"EX":[]});
var COUNT = EXAMPLE.EX.Count //(this is not working)
Best Answer
C
Customer Support
said
over 4 years ago
Hi Alberto,
Count is an operation that you perform on a mongo cursor. A findOne query will only ever return one result. If you're trying to get the length of the array use EXAMPLE.EX.length.
Count is an operation that you perform on a mongo cursor. A findOne query will only ever return one result. If you're trying to get the length of the array use EXAMPLE.EX.length.
Regards,
Liam
A
Alberto Martinez
said
over 4 years ago
Hello Liam,
var COUNT = EXAMPLE.EX.length; is not working
Customer Support
said
over 4 years ago
Hi Alberto,
Is the array "EX" inside of the object who's id is their playerId ? Your query looks wrong here. Currently its set up to find a document for that player that contains an empty array.
Regards,
Liam
A
Alberto Martinez
said
over 4 years ago
In test harness, "EX" returns this:
and thats stored in a runtime collection like this:
Alberto Martinez
Hello everoye, it's a very simple question, how do i get the lenght from an array that i got from a runtime collection in cloud code?
var EXAMPLE = Spark.runtimeCollection("RuntimeCollection").findOne({"_id": Spark.getPlayer().getPlayerId()},{"EX":[]});
var COUNT = EXAMPLE.EX.Count //(this is not working)
Hi Alberto,
Count is an operation that you perform on a mongo cursor. A findOne query will only ever return one result. If you're trying to get the length of the array use EXAMPLE.EX.length.
Regards,
Liam
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstCustomer Support
Hi Alberto,
Count is an operation that you perform on a mongo cursor. A findOne query will only ever return one result. If you're trying to get the length of the array use EXAMPLE.EX.length.
Regards,
Liam
Alberto Martinez
Hello Liam,
var COUNT = EXAMPLE.EX.length; is not working
Customer Support
Hi Alberto,
Is the array "EX" inside of the object who's id is their playerId ? Your query looks wrong here. Currently its set up to find a document for that player that contains an empty array.
Regards,
Liam
Alberto Martinez
In test harness, "EX" returns this:
and thats stored in a runtime collection like this:
"EX":[{"testValue":03},{"testValue":23},{"testValue":00},{"testValue":03}{"testValue":03},{"testValue":45}]
Customer Support
Hi Alberto,
In that case use this as your query to find the document.
var EXAMPLE = Spark.runtimeCollection("RuntimeCollection").findOne({"_id": Spark.getPlayer().getPlayerId()});
Then use var COUNT = EXAMPLE.EX.length; to get the length.
Regards,
Liam
Alberto Martinez
Thanks!
-
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