Jump to content
  • Advertisement
Sign in to follow this  
mercutio604

GameSparks JSON MongoDB syntax issues? I am not getting back anything from my query

This topic is 415 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Anyone here familiar with GameSparks?
I am trying to make a collection (don't know if I am doing it right I am not well versed in JSON yet):

Spark.save("characterCollection", {
"characters" : [
{
"id" : 1,
"name" : "spec1",
"hitPoints" : 5,
"movement" : 3,
"strength" : 3,
"defense" : 3,
"range" : 1,

"sprite" : "spec1",
"avatar" : "spec1"
},
{
"id" : 2,
"name" : "spec2",
"hitPoints" : 5,
"movement" : 3,
"strength" : 3,
"defense" : 3,
"range" : 1,

"sprite" : "spec2",
"avatar" : "spec2"

}
]
});
Then I am trying to get the data from by searching via name "spec1", again I don't know if I am doing it right not familiar with that either >.<"

var characterList = Spark.metaCollection("characterCollection"); // this one works fine i think

var result = Spark.metaCollection('characterCollection').findOne({"characters" :{ "name" : "spec1"}});
Spark.getLog().debug(result); // result listed as null

Share this post


Link to post
Share on other sites
Advertisement

Spark.save returns a boolean for success/failure and the below code goes through success branch.

i changed the JSON formatting a bit to something i think is closer to right:

if(Spark.save("characterCollection", {
    "_id" : 0,
    "name" : "spec1",
    "hitPoints" : 5,
    "movement" : 3,
    "strength" : 3,
    "defense" : 3,
    "range" : 1,
    
    "sprite" : "spec1",
    "avatar" : "spec1"    
}))
{
     Spark.getLog().debug("added");  
}
else
{
     Spark.getLog().debug("not added");  
}

var cursor = Spark.runtimeCollection("characterCollection").find();
var current = cursor.curr();

in the debugger type thingy called test harness it shows "current" as null in this version.

Share this post


Link to post
Share on other sites

Hi Mercutio604

It looks like you're saving a single document with a single field ('characters'), which contains an array of objects. The query's failing because there is no matching document in the collection
 
If you change your Spark.save() stuff to:
 
Spark.runtimeCollection("characterCollection").insert([
{"id":1,
....
},
{"id":2,
....
},
...
]);

it should do what you want (i.e. create a separate document in the collection for each element of the array).
 
If not, or if you have any other questions about using GameSparks, please do not hesitate to get in touch with our support team via https://support.gamesparks.net/support/home we'd be happy to help in any way we can!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!