External Database

Hi Everyone!

I am trying to setup an external database for my game (saw MongoDB is a good one). I found this close to what I’m looking for Connecting an EXTERNAL Database to your ROBLOX GAME but I dont know where to put the python script in MongoDB. Also he says the system is not secure, would anyone know how to make it well secured?

2 Likes

I think you do have to make sure your sending to your external database (Luau and Python) and it’s not wrong type of data which the script requires it and etc.

you have put security in Python and Luau’s function for taking care of data
there is actually checks (of if request reaches it’s success and that’s it) in his code but stored it in ServerStorage.

Python and Luau (roblox’s version) knowledge

You connect it to URL of your MongoDB and i recommend placing somewhere where is MongoDB

Encryption
Checks for bad input/data
Storing urls and such to important data in secrets
etc.

Microlosofto already gave good examples above. Only allow client to do bare minimum, to mitigate any injection attempts or if url to datastore leaks, etc.
Here’s a link to basic checklist about security (14 year old thread, not sure how much of it is true in 2025 anymore): https://serverfault.com/questions/237762/how-to-make-a-secure-mongodb-server

Thanks for the information. And can you help me where to put the python script / making the actual connection of roblox to the MongoDB server?

I personally haven’t had any reason to use external datastore in my projects (yet).
Personally i’d host the python script on same server as the MongoDB, but it depends on your configuration.
For the connection between both roblox and MongoDB, i’d say i’d use HttpService or WebSockets when they’ll reach out of studio-only. You’d need to just format the Http requests and posts and I guess you are good to go.

Documentation on HttpService (https://create.roblox.com/docs/reference/engine/classes/HttpService) talks well about APIs

I dont know where to put the python script in MongoDB

The link you posted is running a flask server (at http://localhost:5000) on his local machine. Flask is a python framework to create http servers. To use in production you’d run it on a cloud provider like AWS, or https://www.pythonanywhere.com/ seems like a simple option with a free tier.

Also he says the system is not secure, would anyone know how to make it well secured?

On your flask server you’d add authentication. Usually done with a user login and JWT but you could get away with a simple hard coded API key since the client of this API (meaning the Roblox server making the request) is also controlled by you.

You’d have to modify or rewrite the Roblox module this guy wrote to actually add that api key to the requests e.g. as a query param or a header.

1 Like

Thanks for the reply, that helps a lot

What exactly is your use for an external database? I would always recommend going with Roblox datastores if you can get away with it, as then you don’t have to worry about having an external server, which might have to scale with the growth of your game, and also usually isn’t free unless you self host, or use a free (probably crappy or not so reliable) provider?

If you don’t need the external database to be online 24/7, you can host the server on your own personal pc. If you need it up 24/7, if you self host, your pc or server would have to be on 24/7, and you wouldn’t have the reliability and up time that providers have

1 Like