I’m attempting to connect MongoDB to Roblox with HttpService, and I already have MongoDB connected with a website, however, I am having issues with GetAsync().
I am kind of new to using HttpService with things like MongoDB, so I’m not sure where to go from here. I’ve used JsonDecode and assigned it to a variable, but it’s acting up and not printing everything in the table when I try to loop through it.
If anyone knows how to properly do this, it would be appreciated.
I was doing something like this to see if their name existed in the table, but it didn’t work the way I expected it to.
local HTTP = game:GetService("HttpService")
local URL = "private"
local DATA = HTTP:GetAsync(URL)
DATA = HTTP:JSONDecode(DATA)
for i,v in pairs(DATA) do
print(i)
print(v)
end
Edit: I tried using the method you did as well, and for some reason it’s not working.
What do you mean by “it’s not working”? What kind of output do you expect to see? In your example, assuming DATA is the same json, it looks like it would print “1” then “table: 0x…” because the root of the json is an array with one dictionary in it.
I noticed in an earlier screenshot that the root element isn’t an array but the dictionary, so you could probably try DATA['data'][1]['username']. If that doesn’t work either, try adding print(DATA) before you use JSONDecode to see what it’s actually getting.