Ad

Query API And Database Using Express And Mongodb

- 1 answer

I need some help with my logic/approach please. I am wanting to create a gaming server list. So people can add their server by entering in

title, IP, port, about.

However on the homepage I also want to display how many players and whether it is online or not. If its offline I dont want to display it. Now for this I can query an api which returns a string like.

{"players_online":22,"max_players":150,"gametype":"TNT"}

These values will change every 60 seconds usually.

What is the best approach to merge the 2 together? I want to store the server basic info in the db but things like players_online and whether the server is up needs to be checked at least every 60 seconds.

Ad

Answer

As per my experience combining both will result in big mesh, I suggest would suggest following:

Job 1: Update all your user's active status, potentially you can have a CRON job that will check if your user is on-line or not and update the Database (I would nor recommend this, rather use some cache and update that cache periodically).

Job 2: Create schema that will make less query to database

gameId -> gameName -> gammerId

1  ->   NFS -> g01
1  ->   NFS -> g02
2  ->   CS  -> g01

or (my recommended schema)

gameId -> gameName -> listOfGammers
1 -> NFS -> g01, g02, g03
2 -> CS ->  g02, g05

In this way you make less query on your database, if you have 100 users in single game you can still get all the gammerIds in signle row + you already have list of users which are online from the cache.

Hope that helps

Ad
source: stackoverflow.com
Ad