Roblox To MongoDB Connector Module - Open Sourced

Hello, this module can help you connect to your MongoDB Datastore from Roblox, with nothing to do from your side, but just initializing the data for the client when they join.

Note: As of September 2021, I have stopped maintaining this module. I won’t be able to assist you with any further issues or code that might break due to future updates.


WHERE TO GET IT

As I told earlier, you will need to get a Roblox Module & The Code for the NodeJS Web server to interact with the MongoDB API. There are others options like MongoDB Realm I believe, but I just like to keep it this way for some reason.

Roblox Module:

NodeJS Server Code:

SETUP PART

I should say this requires some time to setup.

Expand This

Because it is an external database, we will use HttpService internally in the module & the requests will be protected using passwords in base64 encoded form, now people might say this is not secure, if you want you can implement an advance Security system yourself :slight_smile:

Step 1: After you download the github source code, you need to make a .env file for the password and usernames for Connecting to Roblox & MongoDB. After that in the .env write down the following:

USERNAME=Testing
PASSWORD=Testing
MONGO_USER=Neil
MONGO_PASS=TestingPass

Basically USERNAME & PASSWORD are related to the Roblox Connection Credentials, which you can set yourself and the MONGO_USER and MONGO_PASS are related to
MongoDB Connection which you can set too.

Step 2: Go To MongoDB, Create a new Project, and then a new cluster. Then create your Access credentials according to what you had in your .env file for MongoDB, and then allow access from everywhere in Network Access. Then get your MongoDB Connection string, and paste it down in the mongoose.connect part in server.js and then replace the part where you need to pass the Mongo Username and password, kind of like this example, except the connection string should be yours:

mongoose.connect('mongodb+srv://${mongoUser}:${mongoPass}@cluster0.i3et1.gcp.mongodb.net/testing?retryWrites=true&w=majority'

Step 3: Then first type in npm install in the root directory, to install all dependencies and Then start your server with npm start in terminal, in the root directory. I used ngrok tunneling service just for testing, you can host your web server at heroku or something.

Step 4: Once you hosted it, copy the ngrok Url, and then paste it in your Roblox module’s Configuration part’s Server variable and then also configure the Username and password in there according to the ones you created in your .env file earlier


HOW TO USE IT

I actually made the Functions quite like Datastore2, but its not a copy of it, I just did because I felt like. So basically, I made only the simple functions for saving / Getting Data right now, so an example usage would be like (Setup using the guide above first.):

local Rmc = require(script.Parent.RobloxMongoConnector)
local players = game.Players

players.PlayerAdded:Connect(function(plr)
	local coinStore = Rmc:GetStore("Coins", plr)
	print(coinStore:Get(50))
	
	wait(5)
	
	coinStore:Set(100)
	print(coinStore:Get(50))	
end)

Methods

  1. Rmc:GetStore("StoreName", playerInstance)

    Basically create or get an existing store, for using the :Get and :Set methods On.

  2. Store:Get(DefaultValue)

    This method accepts a default value to be used if there isn’t data for the player previously.

  3. Store:Set(Value)

    This method accepts the value to update in the store.

You don’t need to do anything for saving actually, everything is done internally in module :slight_smile:

The :Get method actually is similar to DataStore2’s except its not how it works internally.


:

Why Should You Use MongoDB?

  1. You can store upto 16 Mb in a Document (Think of it as a key)
  2. MongoDB is really fast in querying
  3. Data is stored on the Cloud, and you also get an UI to manage all your data. Which makes it a lot easier.

Downsides

  1. I think there is only this downside, as for me, MongoDB’s costs increase if your storing alot of data when your game gets larger.
Expand

If you want to know more about what MongoDB is, I actually found a some good articles:
Beginners Guide: MongoDB Basics | MongoDB
Everything About MongoDB — Part 1 | by Sahitya Kumar Suman | Medium

33 Likes

I would recommend using MongoDB for heavy data usage or at least critical data usage. It is more advanced so this may not be for beginners.

4 Likes

This is great if you want to create an external service that connects to your Roblox game such as a Dis Bot for any purpose like Moderation banning and messaging. I have yet to test it but I think as long as the module works, anything is possible :grinning:
MongoDB is very fast and it can store a lot online. If you are a student, I am pretty sure you get upgrades for free.

2 Likes

So I just tested it and yes it does work however it doesn’t seem to support boolean data types which is fine with the replacement of 0 and 1s. I have created a connection between Roblox and my discord ban bot. Thanks for the resource, it saves a lot of time.

Oh and another thing, I dont really use mongodb but Im pretty sure theres some deprecation in the code.

Edit: noticed that you only store strings?

1 Like

I love MongoDB and use it for a lot of web applications and projects! Thank you for making this :slight_smile:

1 Like

Amazing project! It works as intended, thank you so much for making this!

1 Like

I’m a bit new to this and all but, how would I go to the website to get the data, for example, when i go to https://(website here)/get-data/test i get {"Data":null} then when I reload it i get {"Data":""}. How do I set the data??

3 Likes

Hey this is good and all but I dont want to save the data to a player I want to be able to just call and save data from a single table how do I do that?

1 Like

No way has this been created woahh. I use mongo for a load of things to do with roblox this is gonna be a real asset, thank you!

1 Like

Thanks so much for this wrapper, been waiting for this! :smile:

1 Like

So it says the data was saved… but I cannot see it in mongo and there are not server errors… Help please?

1 Like

Does MongoDB have session lock? A feature that prevent’s common bugs like item duplication or something that comes close to it.

Is this still in development and still gets updates? I’m looking for a MongoDB roblox connecting because my friend is getting me a database link so I can try to do it. (not trying to bump the topic)

It work with Railway mongo right?

Of course it should. Railway is just another host that hosts MongoDB for more people to use.

am wondering if i could use it to store my leaderstats?

Yes, you can use this to save player data such as leaderstats.

ok i will just try my best, because i am bad in scriptiing

Help me with that error please