Forum BigDB How To Get "Count" of Table ?

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

How To Get "Count" of Table ?

Postby kidkid » January 14th, 2011, 11:27 am

Hi,

I want to upload object with the key is the same with number objects in db at that time.
So I want to know how many records are there in my table.

Currently, I don't find any function to do this so I just think about adding a "count" object.
like :
Table: XYZ
Obj: Count
Property: value: 10

So, at the time I want to upload, I could get this variable for my object key and increase it.
But It will be has some problems if I get error in update count value.

Do there has other method to do this ?
kidkid
 
Posts: 54
Joined: December 1st, 2010, 4:43 am

Re: How To Get "Count" of Table ?

Postby Henrik » January 14th, 2011, 11:37 am

Remember that BigDB is not like a regular SQL Database, it's distributed and highly scalable, and to achieve that some features found in regular databases are not available. Getting a count of the number of objects in a table is one of those, and is not possible to do.

Your idea of storing the count in another object will probably fail over time, it will become less and less accurate.

So, let's take a step back. Why do you need to know how many objects are in a table? What are you trying to achieve?
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: How To Get "Count" of Table ?

Postby kidkid » January 14th, 2011, 11:43 am

Example I want to know how many player has joined the game ?
kidkid
 
Posts: 54
Joined: December 1st, 2010, 4:43 am

Re: How To Get "Count" of Table ?

Postby TobiasW » January 14th, 2011, 12:16 pm

Is it real-time / in the same room? Then you could just ask the server.

Is it turn-based / not all happening in the same room? Then you could/should have a "Game" BigDB object saving the number of players. Should be accurate enough for that. Though... you'll probably not only want to know the number of players in the game but their other data too, won't you? So you could just get the players and count them locally.
User avatar
TobiasW
 
Posts: 59
Joined: August 29th, 2010, 12:31 am

Re: How To Get "Count" of Table ?

Postby batiali » February 18th, 2011, 11:36 am

I'm using playerio for a website where I ask questions to people and get answers back.
So, these questions are in database, a table called "Questions".
I have the same problem. I need to know how many questions are there so I can get one randomly. And when user clicks "SKIP" button, I can get another one, randomly again. (And I don't want to load every question to only pick one of them randomly.)
I'm thinking of the same solution as kidkid. Setting up a count object in that table and whenever a question is added by an admin, I should check every questions in the database and change the count.
Any other solutions?
batiali
 
Posts: 29
Joined: August 11th, 2010, 2:53 pm

Re: How To Get "Count" of Table ?

Postby Henrik » February 18th, 2011, 1:44 pm

If you know you only add items rarely, then storing a count is the best way, since you don't do writes in parallell, you can have lots of error correction to make sure it really happens, and you can even afford to do a count of all items before storing the count.
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm


Return to BigDB



cron