Atlas
MongoDB Developer Centerchevron-right
Developer Topicschevron-right
Productschevron-right
Atlaschevron-right

Storing Roblox Game Data in MongoDB Atlas Using Rongo

Caden ScottPublished Aug 31, 2022 • Updated Aug 31, 2022
AtlasData API
Copy Link
facebook icontwitter iconlinkedin icon
random alt
Rate this article
star-empty
star-empty
star-empty
star-empty
star-empty

Introduction

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.

Prerequisites

Before you can start using Rongo, there are a few things you’ll need to do.
If you have not already, you’ll need to install Roblox Studio and create a new experience.
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!

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.
Downloading the Rongo model
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.

Setting up Rongo in your game

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!
Refer to our documentation for more information on the functions.
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!

Using Rongo to save player data

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:

Conclusion

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.

Copy Link
facebook icontwitter iconlinkedin icon
Rate this article
star-empty
star-empty
star-empty
star-empty
star-empty
Related
Article
Exact Matches in Atlas Search: Beginners Guide

Aug 30, 2022
Tutorial
Microsoft Blazor Tutorial (1/5): Building a Status Page

Sep 07, 2022
Quickstart
MongoDB Atlas Serverless Instances: Quick Start

Jun 28, 2022
Podcast
Atlas 5-Year Anniversary Podcast Series Episode 1 - Onramp to Atlas

May 16, 2022
Table of Contents