Dictionary changing order at runtime but not in playtest which breaks JSON encoding

I am trying to setup a function for a database I am using for a utility in-game, most of the other functions for indexing/searching/changing documents in the database work correctly in studio playtest,

however when I run the game through the website after publishing, the tables that I use to create the request change their order which ends up breaking the JSON encoding as the table must be in a certain order.

For instance, the filter field I need in order to update a document would be formatted this way(this is also how it’s formatted in the module, which makes this make even less sense):
Filter = {["data."..FilterField.."."..FilterSubfield] = {["$regex"] = tostring(Key), ["$options"] = "i"}}

and this works when I run the game through studio, yet for whatever reason when I run the game through the website, I get this instead:

Filter = {["data."..FilterField.."."..FilterSubfield] = {["$options"] = "i",["$regex"] = tostring(Key)}}

This results in a bad request from the database.

This doesn’t only happen with this line of code, it happens with the update function as well, the only solution I could think of is to preformat the filter field as JSON as a string and concatenate the values I need, but I feel like there’s a better way to do this, none of my other functions have required me to do that.

I don’t think I can change the dictionary order either since it’s a dictionary, so I’m not really sure what else to do.

While there may be a better way, I don’t think they’ll have any major performance difference from this solution, unless they involve “fixing” the dictionary.

I’d personally run with this approach for the time being.

1 Like

While I agree, it results in inconsistent code since almost every other function within the same module has the same filter field and haven’t had any problems.
For now it’s what I am doing though.

1 Like