Storing Roblox Game Data in MongoDB Atlas Using Rongo
Rate this article
This article will walk you through setting up and using Rongo in your Roblox games, and storing your data in MongoDB Atlas. Rongo is a custom SDK that uses the MongoDB Atlas Data API.
We’ll walk through the process of inserting Rongo into your game, setting Rongo up with MongoDB, and finally, using Rongo to store a player's data in MongoDB Atlas as an alternative to Roblox’s DataStores. Note that this library is open source and not supported by MongoDB.
Before you can start using Rongo, there are a few things you’ll need to do.
Next, you’ll need to set up a MongoDB Atlas Account, which you can learn how to do using MongoDB’s Getting Started with Atlas article.
Once you have set up your MongoDB Atlas cluster, follow the article on getting started with the MongoDB Data API.
After you’ve done all of the above steps, you can get started with installing Rongo into your game!
The installation of Rongo is fairly simple. However, you have a couple of ways to do it!
First, head to the Rongo library page and press the Get button. After that, you can press the “Try in studio” button, which will open Roblox Studio and insert the module into Studio.
If you wish to insert the module into a specific experience, then open Roblox Studio, load your experience, and navigate to the View tab. Click on Toolbox, navigate to the Inventory tab of the Toolbox, and locate Rongo. Or, search for it in the toolbox and then drag it into the viewport.
You can download Rongo from our Github page by visiting our releases page and downloading the Rongo.rbxm file or the Rongo.lua file. After you have downloaded either of the files, open Roblox studio and load your experience. Next, navigate to the View tab and open the Explorer window. You can then right click on ServerScriptService and press the Insert from file button. Once you’ve pressed the Insert from file button, locate the Rongo file and insert it into Roblox Studio.
First of all, you’ll need to ensure that the Rongo module is placed in ServerScriptService.
Next, you must enable the **Allow HTTP Requests **setting in your games settings (security tab).
After you have done the above two steps, create a script in ServerScriptService and paste in the example code below.
The above code will allow you to modify your collection by adding data, removing data, and fetching data.
You’ll need to replace the arguments with the correct data to ensure it works correctly!
To fetch data, you can use this example code:
You can then print the result to the console using print(Result).
Once you’ve gotten the script setup, you’re all good to go and you can move onto the next section of this article!
This section will teach you how to save a player's data when they join and leave your game!
We’ll be using the script we created in the previous section as a base for the new script.
First of all, we’re going to create a function which will be fired whenever the player joins the game. This function will load the players data if they’ve had their data saved before!
In the script above, it will first create a leaderstats folder and gold value when the player joins, which will appear in the player list. Next, it will fetch the player data and set the value of the player’s gold to the saved value in the collection. And finally, it will give the player an additional five golds each time they join.
Next, we’ll make a function to save the player’s data whenever they leave the game.
This function will first fetch the player's gold in game and then update it in MongoDB with the upsert value set to true, so it will insert a new document in case the player has not had their data saved before.
You can now test it in game and see the data updated in MongoDB once you leave!
If you’d like a more vanilla Roblox DataStore experience, you can also use MongoStore, which is built on top of Rongo and has identical functions to Roblox’s DataStoreService.
Here is the full script used for this article:
In summary, Rongo makes it seamless to store your Roblox game data in MongoDB Atlas. You can use it for whatever need be, from player data stores to fetching data from your website's database.
Learn more about Rongo on the Roblox Developer Forum thread. View Rongo’s source code on our Github page.