Sign In Register

How can we help you today?

Start a new topic
Answered

How to delete documents when using game data service on cloud code

Hello everyone,

I would like to know if  there is a way to delete an entire doc when using Game Data Service javascript cloud code.


I am expecting to find out something like


Spark.getGameDataService().deleteItem("MyCustomDataType", myDocID);



Thanks a lot,


William Siqueira


Best Answer

I found the solution, actually, I put a ticket. My code  would become like this:


var API = Spark.getGameDataService();

var playerEntry = API.getItem("PlayerFriends", playerId);

var data = playerEntry.document().getData();

delete(data[friendPlayerId]);

playerEntry.document().persistor().persist();


Hi William,


Yes, it's possible to delete an item, you just need to retrieve it first, e.g.:


var item = Spark.getGameDataService().getItem(myDataType, myId);

item.delete();


Regards,

Vinnie


Any other way?

"Function delete does not exist"

image

Done! Vinnie was very close:


var item = Spark.getGameDataService().getItem(myDataType, myId);
var document = item.document();
document.delete();


Thanks and regards

Is there a way to delete items in an item...

I have a Game Data that every item contains data like this:



{

  "5bab2f343d3ad204fd306099": {

    "userName": "tester1",

    "userID": "5bab2f343d3ad204fd306099",

    "status": "accepted"

  },

  "5bab3d0d010c7a04f5713cbe": {

    "userName": "tester3",

    "userID": "5bab3d0d010c7a04f5713cbe",

    "status": "accepted"

  },

  "5bab38ca010c7a04f56b0ee1": {

    "userName": "tester2",

    "userID": "5bab38ca010c7a04f56b0ee1",

    "status": "requested"

  }

}


I want to delete one of this embedded item...

something like this:


var API = Spark.getGameDataService();

var playerEntry = API.getItem("PlayerFriends", playerId);

var data = playerEntry.document().getData();

data[friendPlayerId].delete();

I too have got a bit stuck with this, I have managed to get the data[friendPlayerId] but I can't work out how I should go about removing that entry.

Any help would be appreciated!

Answer

I found the solution, actually, I put a ticket. My code  would become like this:


var API = Spark.getGameDataService();

var playerEntry = API.getItem("PlayerFriends", playerId);

var data = playerEntry.document().getData();

delete(data[friendPlayerId]);

playerEntry.document().persistor().persist();

Perfect thanks!

Login to post a comment