Unity WebGL C# error

Hello guys!

Im trying to connect my MongoDB to Unity WebGL with a C# script.

Im getting an incompatibility error for the MongoDB drivers saying “Is the assembly missing or incompatible with the current platform?”

Does this mean I cant use MongoDB with Unity for HTML5 ?

Thank you!

Hi @Bruno_Mataloto,

It depends on how you’re trying to use MongoDB with Unity.

Right now the Realm SDK for Unity does not support WebGL builds. However, if you’re trying to make HTTP requests from your Unity game to some backend, that will work fine.

Just to be clear, you shouldn’t be using the C# driver for Unity because that driver is intended for backend applications, where as a Unity game is considered a frontend application.

Hopefully that helps.

Best,

1 Like

Hello, thank you!

I found webwooks and I am now able to access the data with a HTTP post request.

I just have a question about the webwook function. I wanted to return only a single value from the findOne() resulting document, the problem is that I always get the EJSON format and cant find a way to access the value

My file is as follows :

_id:“sensor.parents_bedroom_temp”
_msgid:“94cfd84e.1db068”
payload:“19.83”
topic:""

And I just wanted the payload value, Im using this :

var doc = context.services.get(“mongodb-atlas”).db("…").collection("…").findOne({ _id :arg1},{"_id":0,“payload”:1});

I also tried to access doc.payload but it returns undefined

Hi @Bruno_Mataloto,

By default a Realm Function will return EJSON. You can get around this by wrapping the object in a JSON.stringify before you return it.

You can learn more about it at this particular spot in the documentation:

Hopefully that helps.

Best,