Forum BigDB How to delete all of the objects in bigdb using c#?

Discussion and help relating to the PlayerIO database solution, BigDB.

How to delete all of the objects in bigdb using c#?

Postby 12345hassan » November 4th, 2018, 5:16 am

The Title explains it all. I made a top10 active list in my game and i want to reset it every week it uses index "active". But from DeleteKeys its too difficult to delete every single object caz there are more than 300 objects and I can't make 300lines for 300 please help
12345hassan
 
Posts: 44
Joined: August 5th, 2016, 11:40 am

Re: How to delete all of the objects in bigdb using c#?

Postby Henrik » November 8th, 2018, 7:04 am

Wouldn't it be much easier to store the week in the objects, and make an index over that as well? That way you just add the current week when you write your scores, and use the index to read scores for the current week.

One simple way to store a week is to store midnight of Monday of the current week as a DateTime. As a bonus, you can get monthly and yearly toplists out of the same BigDB table as well.
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: How to delete all of the objects in bigdb using c#?

Postby 12345hassan » November 9th, 2018, 5:39 pm

Sorry I didn’t understand what you mean. My question is how can I truncate / delete all created objects of a table from my c# when the time of reset is over I have todo it myself from big db isn’t their a way to do it automatically? Delterange gives problem that the property Is int of onlineTime if I convert it to string it won’t add minutes.
12345hassan
 
Posts: 44
Joined: August 5th, 2016, 11:40 am

Re: How to delete all of the objects in bigdb using c#?

Postby Henrik » November 11th, 2018, 1:27 am

My solution to your problem was to simply not do any deletes at all. Instead of treating your table as a single list of most active users for the current week, where you clear it out every week, another solution is to treat it as multiple lists of users, and using indexes to read the current week's list and simply ignoring past weeks. Same result.

But if you really want to delete everything in the table every week, that's certainly possible using DeleteRange, you just need to make sure there is an index that covers all objects, and you should be good. If you have a property in your index that is an int, then call DeleteRange with 0 as the start and MaxInt as the stop, and it should match all objects and delete them.
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: How to delete all of the objects in bigdb using c#?

Postby 12345hassan » November 15th, 2018, 4:12 pm

Error: The start index value of property onlineTime is smaller than the stop value
Code:
PlayerIO.BigDB.DeleteRange("MYDBNAME", "active", null, 0, int.MaxValue);
12345hassan
 
Posts: 44
Joined: August 5th, 2016, 11:40 am

Re: How to delete all of the objects in bigdb using c#?

Postby Henrik » November 16th, 2018, 11:48 pm

If your index is sorted Descending, you need to flip the 0 and int.MaxValue.
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: How to delete all of the objects in bigdb using c#?

Postby 12345hassan » November 17th, 2018, 7:57 am

Thank you for your reply, I will try that as soon as I can, is there a way to give the top 3 prizes?
The top 3 players on the index I want to give them prizes from another table like
Loads top 3 players
Loads the other tables objects of those three
Save their with prizes
Then it delete all objects.
12345hassan
 
Posts: 44
Joined: August 5th, 2016, 11:40 am

Re: How to delete all of the objects in bigdb using c#?

Postby 12345hassan » November 17th, 2018, 9:27 am

The delete is working thank you.
12345hassan
 
Posts: 44
Joined: August 5th, 2016, 11:40 am

Re: How to delete all of the objects in bigdb using c#?

Postby 12345hassan » November 24th, 2018, 7:24 am

12345hassan wrote:Is there a way to give the top 3 prizes?
The top 3 players on the index I want to give them prizes from another table like
Loads top 3 players
Loads the other tables objects of those three
Save their with prizes
Then it delete all objects.
12345hassan
 
Posts: 44
Joined: August 5th, 2016, 11:40 am

Re: How to delete all of the objects in bigdb using c#?

Postby Henrik » November 25th, 2018, 2:48 am

If you have a BigDB Table that contains scores per user, and you want to load the top 3, you need a descending index on the table over the score property, and then you can load the top 3 something like this:

Code: Select all
LoadRange("the table", "the new index", null, null, null, 3, ...)

That gets you the three first objects in the index, and since it's descending and over the score, the first three should be the top 3, which is what you wanted.
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: How to delete all of the objects in bigdb using c#?

Postby 12345hassan » November 25th, 2018, 7:03 am

Henrik wrote:If you have a BigDB Table that contains scores per user, and you want to load the top 3, you need a descending index on the table over the score property, and then you can load the top 3 something like this:

Code: Select all
LoadRange("the table", "the new index", null, null, null, 3, ...)

That gets you the three first objects in the index, and since it's descending and over the score, the first three should be the top 3, which is what you wanted.

How can I give them prizes from other table , here is what i want to do:
Timer ends ( Done )
Loads top3 ( Code Above )
Give them prizes from other table like load the top 3 from STTableofActive and Edit there object in STTableofItems ( Not Done )
Delete all topics ( Done )
The prizes is only left
12345hassan
 
Posts: 44
Joined: August 5th, 2016, 11:40 am

Re: How to delete all of the objects in bigdb using c#?

Postby Henrik » November 26th, 2018, 10:26 pm

If you've loaded the top three users, you have their connectuserid, I guess? Or something that you use as key for each user. And if you're using that same key in the other table, then just call https://playerio.com/documentation/refe ... b#loadKeys which takes an array of keys, and then you'll get those three objects from that table.
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: How to delete all of the objects in bigdb using c#?

Postby 12345hassan » December 27th, 2018, 5:22 pm

Can you tell me how to use LoadKeys, I cannot use it plus the databaseobject used for the top3 loaded (result) gives
Cannot convert from PlayerIO.GameLibrary.DatabaseObject[] to string[]
12345hassan
 
Posts: 44
Joined: August 5th, 2016, 11:40 am

Re: How to delete all of the objects in bigdb using c#?

Postby 12345hassan » January 5th, 2019, 9:26 am

12345hassan wrote:Can you tell me how to use LoadKeys, I cannot use it plus the databaseobject used for the top3 loaded (result) gives
Cannot convert from PlayerIO.GameLibrary.DatabaseObject[] to string[]
12345hassan
 
Posts: 44
Joined: August 5th, 2016, 11:40 am

Re: How to delete all of the objects in bigdb using c#?

Postby Henrik » January 13th, 2019, 8:51 pm

You can't pass in the three databaseobjects of the top three users into LoadKeys, you need to grab whatever string property in those three databaseobjects represent the connectuserid, and then make an array of those three strings, and pass that into LoadKeys.

I don't know exactly what your BigDB tables look like, so it's hard to help you further than this. Which tables in which game are we talking about? I can take a better look if I just know which game and tables.
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: How to delete all of the objects in bigdb using c#?

Postby 12345hassan » January 15th, 2019, 10:08 am

Henrik wrote:You can't pass in the three databaseobjects of the top three users into LoadKeys, you need to grab whatever string property in those three databaseobjects represent the connectuserid, and then make an array of those three strings, and pass that into LoadKeys.

I don't know exactly what your BigDB tables look like, so it's hard to help you further than this. Which tables in which game are we talking about? I can take a better look if I just know which game and tables.

My game : Stick Traders Remake
Active table contains:
onlineTime - int
fbname - string
fbuid - string (connectuserid)
Prize Table: STTableofItems
which contains
connectuserid.items(i want to give top3 some items from here)
12345hassan
 
Posts: 44
Joined: August 5th, 2016, 11:40 am

Re: How to delete all of the objects in bigdb using c#?

Postby Henrik » February 12th, 2019, 4:51 am

Ok, then you could do it something like this:

Code: Select all
LoadRange("STTableOfActive", "active", null, null, null, 3, delegate(DatabaseObject[] topThreeActive) {
    //Now you have the top three objects in Active table.
    //Extract the keys of those three, and put in a string array.
    var keys = new string[]{ topThreeActive[0].Key, topThreeActive[1].Key, topThreeActive[2].Key };
    //Load the objects in the Items table that has those keys
    LoadKeys("STTableOfItems", keys, delegate(DatabaseObject[] topThreeItems) {
        //Change some properties of these three objects
        topThreeItems[0].Set("items.lolface", 1);
        topThreeItems[1].Set("items.elfhat", 1);
        topThreeItems[2].Set("items.tennisracket", 1);
        //Don't forget to save the objects...
    }, delegate(PlayerIOError error) {
        //Something went wrong loading from Items table
    });
}, delegate(PlayerIOError error) {
    //Something went wrong loading from Active table
});
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: How to delete all of the objects in bigdb using c#?

Postby 12345hassan » February 13th, 2019, 9:53 am

Thank you for all your help! Finally it works :)!
12345hassan
 
Posts: 44
Joined: August 5th, 2016, 11:40 am


Return to BigDB



cron