[๐ŸŽ‰ 2.0.0] Rongo - MongoDB API Wrapper for Roblox

Okay, I think you havenโ€™t filled in your ID correctly in the main script, anyways, good stuff!

1 Like

Iโ€™ve been using Rongo for over a year and itโ€™s really working perfectly :sparkles:
Iโ€™ve got no problem, took me a some time to understand how MongoDB was working but itโ€™s actually not difficult and very logical :ok_hand:t2:

Thank you for creating this ! :sparkling_heart:

1 Like

A bit late to this conversation but Iโ€™m struggling with the UpdateOne() function.

This is my script currently:

ReplicatedStorage.Sequel.TALAXY.Events.CreateProfile.OnServerEvent:Connect(function(Player: Player, Title, Name)
	local Data = {}
	
	local Success, Profile = pcall(function()
		return PlayersCollection:FindOne({["UserId"] = Player.UserId})
	end)
	
	Data = Profile
	
	Data["Schools"][Key]["Title"] = Title
	Data["Schools"][Key]["ProfileName"] = Name
	
	warn(Data)
	
	ReplicatedStorage.Sequel.TALAXY.PlayerDetails:WaitForChild(Player.Name).ProfileName.Value = Name
	ReplicatedStorage.Sequel.TALAXY.PlayerDetails:WaitForChild(Player.Name).Title.Value = Title
	
	local UpdateSuccess, UpdatedProfile = pcall(function()
		return PlayersCollection:UpdateOne({["UserId"] = Player.UserId}, Data)
	end)
	
	warn(UpdateSuccess)
	warn(UpdatedProfile)
end)

The UpdateOne() function happens here:

local UpdateSuccess, UpdatedProfile = pcall(function()
		return PlayersCollection:UpdateOne({["UserId"] = Player.UserId}, Data)
	end)

The error is that it keeps returning HTTP 400 (Bad Request). The โ€œUpdateSuccessโ€ returns as true and the โ€œUpdatedProfileโ€ returns as nil.

If you can help with this issue, that would be great.

1 Like

Hey, what does the Data dictionary look like? May be an issue caused by having values in there that canโ€™t be converted to JSON.

1 Like

I fixed this issue. What I basically done is when I used the FindOne() function, I used the data (dictionary) on that and placed it onto a variable.

When sending the variable through the UpdateOne() feature, it wouldnโ€™t update unless i removed the (โ€œ_idโ€) value from the dictionary.

The value automatically sets in MongoDB without having to send it through which is why is I received HTTPS 400.

2 Likes

Rongo has reached version 2.0.0 :tada:

Rongo has reached Version 2.0.0, this is still in early stages and you may encounter bugs.
This change included:

  • A complete rewrite of Rongo internals, updating them to match the current state of the MongoDB Data API
  • Additional authentication types (API Key, Bearer Token and Email/Password)
  • Added additional endpoints (Aggregate)
  • Clearer and more detailed errors & error handling
  • Bug fixes to common issues with 1.0.0

IMPORTANT NOTICE:

Rongo has been updated to version 2.0.0; this is a breaking change, the internals of Rongo has been entirely rewritten to provide a better developer experience and also compatibility fixes, if you are using an older version of Rongo and would like to update, the core change would be the way you initialize a new client, you now need to put the full Data API URL as the first argument and your API key in the second.

5 Likes

Just a quick poll as myself and my team are cooking up something that may be of interest!

Weโ€™re looking to create a hosted API that allows developers to use a self-hosted MongoDB instance within Roblox using Rongo, which is not currently supported.

We may also look into providing a hosted solution for MongoDB as well as an alternative to Atlas.

It would be super helpful if we could get an estimate in terms of costs for this new service, so please fill out the questions below!

if you have less than 1 million monthly requests, you will not be charged anything

At what price would you say is too much? (monthly/per 1 million requests)
  • $15.00 USD (per 1 million requests)
  • $20.00 USD (per 1 million requests)
  • $25.00 USD (per 1 million requests)

0 voters

usage based would be the per 1 million requests, which allows for more scalability, and plan based system would give you a set amount of requests a month, that would not scale

What type of payment modal would work best?
  • Usage based system
  • Plan based system

0 voters

There are pros and cons to each of these options, however weโ€™d definitely like to get your feedback; keep in mind that we also have costs from our end that we must cover (if we didnโ€™t, this service would be 100% free for everyone)

3 Likes

Is there a way to return updated document with data api?

1 Like

I do not believe it is possible to have it returned in the same response however you should be able to send another request after (you might run into some issues with caching, should be able to disable that though, would require a manual edit to the code since it caches automatically); another thing you could do is wait a couple seconds then send another request.

I can publish a fix when I have the time to address the caching issue (if it is in fact that) as I was encountering the inability to get an updated document immediately after updating it.

1 Like

I kinda figured out a way to do it. I created a new HTTPS endpoint in the mongodb Atlas that uses custom function and modified Rongo to use it

exports = async function({ headers, body }, response) {
    const { dataSource, database, collection, filter, update, options } = JSON.parse(body.text());

    const mongoCollection = context.services.get(dataSource).db(database).collection(collection);

    try {
      const updatedDocument = await mongoCollection.findOneAndUpdate(filter, update, options);
      return JSON.stringify(updatedDocument);
    } catch (err) {
      return JSON.stringify({ message: "Error updating document or document not found", error: err })
    }
};

It has some limitations like .findOneAndUpdate() doesnโ€™t support aggregation pipeline but for normal updates it works just fine

update = {["$set"] = {["rap"] = 264}}
print(Collection:FindAndModify({_id = "test2"}, update, {returnNewDocument = true}))

2 Likes

Just discovered you released 2.0.0! Love the changes.

Reading through, so far Iโ€™m very pleased with 2.0.0. As for projects I am using this with, I am working on a MongoDB moderation system for Adonis Admin, under Epix Incorporated.

Cheers!

1 Like

Hey how to do :FindMany without data, if without data return {}, since I keep getting [RONGO] Request returned an error with the following details:
Error message: Failed to find documents: FunctionError: find: query arg must be an object
Status code: 400
Status Message: Bad Request

Hey why canโ€™t I use collection:FindMany({}), it always return

[RONGO] Request returned an error with the following details:
Error message: Failed to find documents: FunctionError: find: query arg must be an object
Status code: 400
Status Message: Bad Request

Edit: I think I found the issue, when you pass empty {}, it will be changed to [] when you use JsonEncode, so you need to replace [] with {} after being encoded

Hey there, due to the way Roblox parses JSON data, it is not possible to pass an empty dictionary as it is automatically converted to an Array in JSON.

An alternative you can use would be the following:

Collection:FindMany({["_id"] = { ["$exists"] = true }}))

This is assuming each document you are referencing has an _id key, which documents should automatically have.

Hopefully this helps!

I can also work on implementing a fix to automatically change [] to {} in the body, however that will need to come in a later release, you should be able to manually do this by using string.gsub, you can replace the code in line 114 with this:

Body = string.gsub(HttpService:JSONEncode(Data),"[]","{}")

(have not tested this, might not work)

Well the easier way is when you already encode, just replace [] with {} within the string

This does not work with the way JSON encoding works.

But it sent me correct result tho?

Oh my bad, thought you were referring to sending the {} as a string "{}" when sending the request, my bad!

Yeah, the second solution I showed in my answer should work fine as it does exactly what you explained!

Would anyone know how to use this to make FFlags? If so, please reply and tell me. First time using this API lol.

Does this also work with 3 party hosting hosting mongodb? Or is it just from the official mongodb site?

1 Like