MongoStore
An alternative to DataStoreService, made with Rongo
v1.0.0
MongoStore is using an outdated version of Rongo, update coming soon
Download on Roblox
Download on Github
View Source
What is MongoStore?
MongoStore is an open-source alternative to Roblox’s DataStoreService.
It makes use of MongoDB in order to save player data (using Rongo as an interface)
MongoStore is currently quite limited in features but it includes the “main” function of Roblox’s DataStoreService, which is :GetDataStore()
. When you run this, you’ll get an object back which behaves similarly to Roblox’s GlobalDataStore
, although MongoStore lacks a couple functions from Roblox’s one.
MongoStore aims to make the transition between DataStoreService and MongoDB as smooth as possible, which is why it behaves almost exactly the same.
MongoStore is licensed under the MIT License
How do I install MongoStore?
If you’d like to install MongoStore, then either grab the model from the Roblox Library or download the file on Github!
Once you’ve gotten either of those, insert it into ServerScriptService
& then you’re ready to start using it!
Scroll down for some usage examples & documentation
Examples
This requires basic knowledge of MongoDB
Setting up the Data API on MongoDB
Follow the steps below to get MongoDB’s Data API Setup
1 - Click on the “Data API” page in MongoDB
2 - Enable the Data API
(make sure to select the sources)
3 - Copy your API ID & store it somewhere safe
(only copy this, don’t copy the entire URL)
4 - Click on the “Create API Key” button
5 - Enter a name then press the generate button
Copy your API key & store it somewhere safe
Once you’ve done all these steps you should be good to go and you’re ready to setup MongoStore in your game!
Using MongoStore in your game
After you’ve set up the Data API & installed MongoStore in your game, you can start using it. Below will teach you the basics of getting it set up!
1 - Create a database & collection on MongoDB
This can be done by clicking on the “Collections” tab in your MongoDB Cluster & then pressing the “Create Database” button
This is what I’ll be calling my database & collection, you can call them whatever you want though.
2 - Create a script in ServerScriptService for MongoStore
3 - Open the script & replace the content with the script below
local ServerScriptService = game:GetService("ServerScriptService")
local MongoStore = require(ServerScriptService.MongoStore) --// Replace this with the location where you placed the MongoStore module
MongoStore:Authorize(APP_ID,APP_KEY) --// Replace these with your App ID & API Key (This is required to use MongoStore)
local DataStore = MongoStore:GetDataStore("DataStore","PlayerData") --// Replace these with your database name & your collection name
--// You can also change the cluster name from the default (Cluster0) by adding an extra argument with your cluster name
This is a basic script which will let you start using MongoStore!
Simple player data script
This example will show you how to create a script which will set & update a players data when they join & leave the game!
1 - Below the base script that you made in the previous example, paste this code:
game:GetService("Players").PlayerAdded:Connect(function(Player)
local success,data = pcall(function()
local Result = DataStore:GetAsync("_"..Player.UserId)
return Result
end)
if not success or not data then
pcall(function()
DataStore:SetAsync("_"..Player.UserId,{["gold"] = 0})
end)
data = {["gold"] = 0}
end
print("Your gold:",data.gold)
Player:SetAttribute("Gold",data["gold"] or 0)
task.spawn(function()
while task.wait(1) do
Player:SetAttribute("Gold",Player:GetAttribute("Gold")+1)
end
end)
end)
game:GetService("Players").PlayerRemoving:Connect(function(Player)
pcall(function()
DataStore:UpdateAsync("_"..Player.UserId,{["gold"] = Player:GetAttribute("Gold")})
end)
end)
This script will fetch the players “gold” when they join the game & then will give the player one gold every second until the player leaves. Once the player leaves, it’ll save the players gold!
2 - Test the script!
Open the game in Roblox Studio & look at output, it should print out the gold you have when you join!
Wait a few seconds then leave the game & rejoin then look at output again, you should see your new gold!
You can also look at your collection on MongoDB to see your gold or other players gold:
3 - Modify the script to your needs
You can now change the script around or remake it to fit your needs!
Documentation
Classes
Functions
Module
function MongoStore:Authorize(AppId: string,AppKey: string) -> boolean
AppId: The ID inside your Data API URL
AppiKey: The API Key which you generated in MongoDB
-- You only need to authorize in a single script --
function MongoStore:GetDataStore(Name: string,Scope: string,Cluster: string?) -> DataStore
Name: The name of your database/datastore
Scope: The name of your collection
Cluster: The name of your cluster (default: Cluster0)
DataStore
function DataStore:GetAsync(Key: string): {[string]: any?}?
Key: The key for the datastore you want to get
function DataStore:UpdateAsync(Key: string,Value: any): boolean
Key: The key for the datastore you want to update
Value: The updated value of the datastore
function DataStore:SetAsync(Key: string,Value: any): boolean
Key: The key for the datastore you want to set
Value: The new value of the datastore
function DataStore:RemoveAsync(Key: string): boolean
Key: The key for the datastore you want to remove
Credits
MongoStore was developed by @Starnamics using Rongo & was made possible by MongoDB
Feel free to use MongoStore in whatever way you want as long as it follows the license terms
Thank you!