Rbx-to-mongo | A MongoDB Data API wrapper

I NO LONGER MAINTAIN THIS. A V2 WILL BE RELEASED WITHIN THIS YEAR.

Hello all! With the release of MongoDB’s beta Data API, I’ve decided to make an API wrapper for it. Please note a small amount of experience with MongoDB is required to use this.

The wrapper is simple to use & open sourced to all.

Firstly, lets move onto a simple tutorial:

The first course of action is to prepare your database. Once you’ve provisioned your database, head on over to Data API

Next, lets select our data sources that we want to be accessible. After that, create an API key and DO NOT SHARE IT WITH ANYONE ELSE!. Copy your key and keep it somewhere safe.

Make sure you also copy the URL endpoint, as we will need it.
image

Okay! You’ve successfully prepared all your materials. Now lets head onto studio! Let’s begin by requiring the module locally or from the web.

local APIModule = require(8772252865)

After that, let’s set our API key and endpoint we got from earlier.

APIModule:New("<API KEY>","<API ENDPOINT>")

Congratulations, you are now ready to begin using the module to its full extent. Let’s insert a test document.

APIModule:InsertOne({name = "Test"},"<DATA SOURCE>","<DATABASE","<COLLECTION>")

should be the name of one of the data sources you selected in Data API. should be the database inside said data source. should be the collection inside that database. InsertOne will return the inserted object IDs after they have been inserted. Congratulations! You have created your first document with rbx-to-mongo!

Okay, lets now find that document.

APIModule:FindOne({name = "Test"},"<DATA SOURCE>","<DATABASE","<COLLECTION>")

Awesome, the API will return the document and all of its elements in a LUA table for you. Now let’s delete the document.

APIModule:DeleteOne({name = "Test"},"<DATA SOURCE>","<DATABASE","<COLLECTION>")

Nice, you’ve learned the basics of the wrapper.

Sometimes adding the Data Source, Database, and Collection in every request can make your code look lengthy. You can use this function to make them automatically passed into the request without having to specify them:

APIModule:Change("<STATIC SOURCE>","<STATIC DATABASE>","<STATIC COLLECTION>")

However, you may be constantly changing collections, sources, or databases. Don’t worry as passed in collections/databases/sources are prioritized over the static one.

Source:

MongoDB Data API Documentation (All functions from here are on the wrapper so read it!):

GitHub (Wiki is being made):

Thanks for reading!
MemAddress

15 Likes

Great tutorial; thanks. Will be using MongoDB in the fututre.

Useful. Been using MongoDB for off-site projects for a long time and I do really like it. May consider trying your wrapper out. Good job!

Very interesting! How come it doesn’t work with serverless instances?

Realm & Serverless instances are not supported by their Data API yet. Currently only Atlas clusters can utilize the API.

1 Like

Amazing resource, breaks down on the clutter created from a server as well as the price of both a cluster and a server. Thank you for this.

Hi everyone! Serverless instances are now supported by the Data API. This module should work with it!

How do I do it with my self hosted mongoDB?

As of now I do not believe the Data API is supported for self hosted instances. The way around this is to create a server using something like express.js and send requests to that server from ROBLOX.