MongoDB and Realms with Unity3D for Mobile Builds Recoomendation

Hello, there!

I have been developing a mobile game in unity for a while now and it is very DB dependent, so I thought that MongoDB was the best alternative and decided to start studying how it works.

My first solution was downloading the Unity-mongo-csharp-driver-dlls, given that it seemed pretty simple to use. I tested several things within the editor and made it work EXACTLY as I wanted by fetching the data using the methods below.

client = new MongoClient(MONGO_URI);
db = client.GetDatabase(DATABASE_NAME);
collection = db.GetCollection<MongoClass>(COLLECTION_NAME);

and then I was able to do whatever I wanted with the data, like fetch all:

List<MongoClass> fetchedList = collection.Find(i => true).ToList();

But, once I had the project built to mobile, It stopped working, as explained in this topic by people with similar issues: MongoDB and Unity il2cpp Mobile Builds.

So I started studying the MongoDB Realm as an alternative and found it very confusing. I believe it is due to the fact that it is still in alpha, but even so, I followed the steps and imported the package from GitHub as orientated, but couldn’t get much farther than that.

What I wish to do is the same as I described above BUT something that still works on mobile builds.

I also came across this topic but couldn’t apply the recommendation: Accessing Realm features with Unity and C#.

For starters I was not able to specify a MongoClient for some reason. This is the error that I get: Realms.Sync.MongoClient 'MongoClient' does not contain a constructor that takes 1 arguments

Anyway, I described thoroughly what I aim to achieve and the problems to do so. I will be waiting for a reply!

Hey, thanks for trying out the early preview of the Realm Unity SDK. Unfortunately, I have mixed answers to your questions. First, the current version of the SDK has only been tested and proven to work as a local database. The sync and remote MongoDB functionalities are not expected to work. Fortunately, most of the issues regarding those have been addressed and we expect to release a new version next week where everything should work in the editor/with the Mono backend.

The bad news is that we’re still working through the IL2CPP problems and we don’t expect most of the functionality to work well there yet. We definitely aim to fully support it, but it’s a contained environment, significantly different from the Mono or .NET runtimes and it takes quite a bit of time to adapt to it.

1 Like

Thanks for the reply!

I see. So, for the time being there isn’t a way to acess a DB in Mongo Atlas through a mobile build? Even with other API’s?

You can use the GraphQL API which can be called with a simple HttpClient.

Could you give me a simple example?
I have some doubts, like, what url do I have to provide?

You can find some examples under the Run GraphQL Operations from a CLI section of the docs. Those showcase using curl, but that should translate fairly easily to the HttpClient API.

@Nicokkam We’d love to hear more about the game you are looking to build with the Realm Unity SDK - drop me a line at ian.ward@mongodb.com and I can let you fill you in on our gaming roadmap for Realm

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.