- Home /
MongoDb in Unity WebGL
Hello people.
I'm trying to access a Mongodb in a WebGL project.
Here is an excerpt from my DbConnector:
using System;
using MongoDB.Driver;
using UnityEngine;
public class DbConnector : MonoBehaviour
{
private static MongoClientSettings _settings = new MongoClientSettings
{
Server = new MongoServerAddress("localhost", 27017),
};
private static MongoClient _client = new MongoClient(_settings);
private static IMongoDatabase _userDatabase;
public static IMongoDatabase GetDatabase(string dbName)
{
switch (dbName)
{
case "user":
if (_userDatabase != null)
return _userDatabase;
break;
}
return null;
}
private void Start()
{
try
{
_userDatabase = _client.GetDatabase("user");
Debug.Log("Loading userdb complete!");
}
catch (Exception e)
{
Debug.Log("can't load user db from server: " + e);
}
}
}
In the editor this works fine, even if the Mongodb is on a server and has authentication.
As soon as I upload it, however, I get this error:
MethodAccessException: Attempt to access method 'MongoDB.Driver.IMongoDatabase.GetCollection' on type '' failed.
The script 'DbConnector' could not be instantiated!
(Filename: ./Runtime/Scripting/ManagedReference/SerializableManagedRef.cpp Line: 225)
_JS_Log_Dump @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
wasm-function[4077] @ wasm-0000006e-4077:22
wasm-function[4090] @ wasm-0000006e-4090:22
wasm-function[4084] @ wasm-0000006e-4084:826
wasm-function[4071] @ wasm-0000006e-4071:518
wasm-function[4626] @ wasm-0000006e-4626:326
wasm-function[4619] @ wasm-0000006e-4619:824
wasm-function[4578] @ wasm-0000006e-4578:192
wasm-function[4664] @ wasm-0000006e-4664:310
wasm-function[6683] @ wasm-0000006e-6683:15
wasm-function[6833] @ wasm-0000006e-6833:97
wasm-function[6832] @ wasm-0000006e-6832:133
wasm-function[6831] @ wasm-0000006e-6831:20
wasm-function[6817] @ wasm-0000006e-6817:4
wasm-function[4579] @ wasm-0000006e-4579:474
wasm-function[4575] @ wasm-0000006e-4575:188
wasm-function[8643] @ wasm-0000006e-8643:416
wasm-function[8573] @ wasm-0000006e-8573:914
wasm-function[9847] @ wasm-0000006e-9847:397
wasm-function[9846] @ wasm-0000006e-9846:25
wasm-function[9844] @ wasm-0000006e-9844:40
wasm-function[9840] @ wasm-0000006e-9840:280
wasm-function[9835] @ wasm-0000006e-9835:157
wasm-function[9704] @ wasm-0000006e-9704:532
wasm-function[9703] @ wasm-0000006e-9703:5
(anonymous) @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
callMain @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
doRun @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
run @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
runCaller @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
removeRunDependency @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
(anonymous) @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
doCallback @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
done @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
done @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
storeLocalEntry @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
(anonymous) @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
(anonymous) @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
IndexedDB (async)
loadRemoteEntry @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
(anonymous) @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
reconcile @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
(anonymous) @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
(anonymous) @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
IndexedDB (async)
(anonymous) @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
success (async)
(anonymous) @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
IndexedDB (async)
(anonymous) @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
success (async)
(anonymous) @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
IndexedDB (async)
(anonymous) @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
success (async)
(anonymous) @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
IndexedDB (async)
(anonymous) @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
success (async)
(anonymous) @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
IndexedDB (async)
(anonymous) @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
IndexedDB (async)
(anonymous) @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
success (async)
(anonymous) @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
IndexedDB (async)
(anonymous) @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
success (async)
(anonymous) @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
IndexedDB (async)
(anonymous) @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
success (async)
(anonymous) @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
IndexedDB (async)
(anonymous) @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
success (async)
(anonymous) @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
IndexedDB (async)
(anonymous) @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
IndexedDB (async)
(anonymous) @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
IndexedDB (async)
(anonymous) @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
IndexedDB (async)
(anonymous) @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
IndexedDB (async)
(anonymous) @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
(anonymous) @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
IndexedDB (async)
getDB @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
getRemoteSet @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
(anonymous) @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
getLocalSet @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
syncfs @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
(anonymous) @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
syncfs @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
(anonymous) @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
(anonymous) @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
callRuntimeCallbacks @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
preRun @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
run @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
runCaller @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
removeRunDependency @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
receiveInstance @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
receiveInstantiatedSource @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
Promise.then (async)
doNativeWasm @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
(anonymous) @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
(anonymous) @ blob:http://wcontrib…8e6d-f5ecdf83dedb:8
UnityLoader.loadCode.Module @ 3998187….js:4
i.onload @ 3998187….js:4
load (async)
loadCode @ 3998187….js:4
processWasmFrameworkJob @ 3998187….js:4
i.callback @ 3998187….js:3
setTimeout (async)
i.complete @ 3998187….js:3
(anonymous) @ 3998187….js:4
r.worker.onmessage @ 3998187….js:3
The app itself goes. Only not the connection to the Mongodb.
The dlls I have among other things from: https://github.com/mongodb/mongo-csharp-driver
or from: https://github.com/mongodb/mongo
or here: https://github.com/Julian23517/Unity-mongo-csharp-driver-dlls
The latter from the post (at the bottom) by: https://answers.unity.com/questions/618708/unity-and-mongodb-saas.html
Nothing has come up with a solution yet.
Here are my ProjectSettings:
and here:
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Gameobjects not in the right position 0 Answers
Issue with shaders and WebGL 1 Answer
Flip over an object (smooth transition) 3 Answers