S
S
seenotevil2015-03-31 10:29:45
MongoDB
seenotevil, 2015-03-31 10:29:45

How to organize a connection of many games with their database?

I am developing a small platform for playing mini-games based on node.js and websocket, the player comes in to create a certain game, an instance of a certain game is created on the server, games such as balda require a connection to their database. The question is how to create and close a connection to the database (using mongodb). Let's say there are 8 simultaneously running games, create a new connection each time and close it after each game, or keep one connection to the database and close it after the last game is completed? Or use one database for all games and open a connection when the platform application itself is launched?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Timur Shemsedinov, 2015-03-31
@seenotevil

When you do a MongoClient.connect using the mongodb driver, a database connection pool is created and opened and closed as needed, so don't worry and use one db connection for all db requests. And if you have a platform for games, then store everything in one database, then it will be easier to backup and restore, and if you think carefully, then some kind of generalized structure will emerge over time.

K
Konstantin Kitmanov, 2015-03-31
@k12th

Give up PHP habits - no need to connect and disconnect from the database with each request. It is enough to connect at the start of the application.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question