Sign In Register

How can we help you today?

Start a new topic
Answered

Using NoSQL

Can you provide some examples on how to use NoSQL part of the control panel?

It doesn't have a field where we can put raw NoSQL query and tabs for different actions are confusing and unclear what we need to put where for it to work. 

I am trying to do a simple find all operation but saying db.player.find() or player.find() or just find() doesn't seem to work. What exactly are we supposed to do? Is there a specific syntax I am unaware of?


Best Answer

Hi Ana


In the find tab you put the arguments you would in db.player.find(). Clicking submit in the find tab actually does a db.<collection>.find() internally, and the fields allow you to control the parameters passed.


For a find all (db.player.find()) leave the query field empty


For a selective find, something like db.player.find({"userName" : "gabriel"})  put {"userName" : "gabriel"} in the query field.


The interface was inspired by MongoHub


Hope that helps!


Gabriel


Answer

Hi Ana


In the find tab you put the arguments you would in db.player.find(). Clicking submit in the find tab actually does a db.<collection>.find() internally, and the fields allow you to control the parameters passed.


For a find all (db.player.find()) leave the query field empty


For a selective find, something like db.player.find({"userName" : "gabriel"})  put {"userName" : "gabriel"} in the query field.


The interface was inspired by MongoHub


Hope that helps!


Gabriel

Aaa, so that's how it works!

Thank you for the info.

I've never used MongoHub, I always wrote raw NoSQL so the interface was unfamiliar. Thank you for clearing that up. Now that I understand how to use it, it is quite handy to skip writing db.player.find!

Another NoSQL question...in cloud code, how can I query a collection for a specific Id? Using "ObjectId", as specified in the MongoDB manual, isn't recognized in the cloud code.


Thank you!

You can use the mongo extended json format to achieve this


Spark.runtimeCollection("test").findOne({ "_id": { "$oid": "5331a09ce4b0489502a73b9c" }})


This is the same format you see for _id fields in the NoSql explorer.


Hope thats useful!


Gabriel


1 person likes this

Great! Thank you!

One more NoSQL question. In cloud code, is there a way to query gamespark's collections like "player" or "challengeInstance"?
Thanks.

 

Hi Antonio,

Unfortunately there is no direct way to access the player and challenge instance collections from Cloud Code

 

There are however Cloud Code API’s for working with the current player and challenges. There is more information about this found here in the manual but here are the links I am referring to:


Spark Player:

https://docs.gamesparks.net/documentation/cloud-code-api/spark-cloud-code-api/sparkplayer

 

Spark Challenges:

https://docs.gamesparks.net/documentation/cloud-code-api/spark-cloud-code-api/sparkchallenge

 

Also this is how you get hold of the SparkPlayer and SparkChallenge object:

https://docs.gamesparks.net/documentation/cloud-code-api/spark-cloud-code-api/spark#getPlayer

 

The NoSQL Explorer allows the developer to access the Player and ChallengeInstance collections and allows the data to be exported for offline analysis.

 

If you have any further questions please let us know.

Kind Regards,

Jamie

 

Ok. Thank you!

 

Is there any way to use NoSQL code to directly do things like renaming a (runtime) collection?

Login to post a comment