Sign In Register

How can we help you today?

Start a new topic
Answered

Getting data from player collection

Hello.


I need to get some data from player collection in Cloud Code, lastLogoutTime. But it always returns an empty array when I try somehting like this:


var results = Spark.metaCollection('player').find({ "scriptData.lastLogoutTime" : { "$gte" : "2015-06-09T04:55:57.783Z", "$lt" : "2015-06-09T05:25:57.000Z" } , "currency1": {"$lt" : 20}}).toArray();


How can I achieve this?


Best Answer
Hi Enrique,

Player's info would be in the runtimeCollection instead of the metaCollection. A meta collection is a read-only collection, meaning the only way to write to it would be throught the NoSQL editor in GS. It's meant to be this way as it's design is to hold persistent game data. The runtime collection can be read and written to, and that is where I assume you have your 'player' collection.

This link would help you setup your lastLogoutTime: https://support.gamesparks.net/support/discussions/topics/1000045698

The time stored in the db would be time in ms since Jan 1, 1970 (i.e. 1434085158247), so your preset date ("2015-06-09T04:55:57.783Z") should be converted to a number first using the JS Date object for your "$gte" and "$lt"to work.

 


Answer
Hi Enrique,

Player's info would be in the runtimeCollection instead of the metaCollection. A meta collection is a read-only collection, meaning the only way to write to it would be throught the NoSQL editor in GS. It's meant to be this way as it's design is to hold persistent game data. The runtime collection can be read and written to, and that is where I assume you have your 'player' collection.

This link would help you setup your lastLogoutTime: https://support.gamesparks.net/support/discussions/topics/1000045698

The time stored in the db would be time in ms since Jan 1, 1970 (i.e. 1434085158247), so your preset date ("2015-06-09T04:55:57.783Z") should be converted to a number first using the JS Date object for your "$gte" and "$lt"to work.

 

If you are looking for the lastSeen variable in 'player', it would be through

 

Spark.setScriptData("response", Spark.getPlayer().getLastSeen());