Connecting to db in MongoDB atlas through desktop app and mobile app (android, Java)

Hi, I’m a novice/junior developer and I’m trying to develop a desktop app and android app. Both should connect to the same db that I’m hosting in MongoDB Atlas. It’s for a college project, essentially, and I’d be using the free tier. I have some experience with MongoDB Atlas, and it seems like the best deal considering I can’t pay.

So I have a model of Java objects to match the elements of the collections and whatnot. I have experience doing this interacting with Atlas directly in Java desktop apps. I’ve added a lot of functionality to all the classes and heavily tested them.

However it seems that the API for interacting with such elements in mobile devices (the Realm stuff) is completely different. They require things from your model classes like usage of special annotations, extending RealmObject and other stuff that would be irrelevant for the model in the desktop application.

And as far as I know the Java SDK doesn’t work in Android, so using this “Realm” feature would be the way to go right?

I’m just wondering if anyone could give me some rough guide, tip or resource to try to solve this conundrum that I’m presenting since this has been frustrating me for days now. I’d rather not have to maintain two versions of the same code.

Any help will be hugely appreciated!

If you separate database for Mobile and Desktop the in same Altas project create two user one for App and another for desktop.

Create user form above YouTube video.

And can deploy app user in app code deployment string and desktop app user in desktop deployment string.

Hi, that’s interesting and may be useful but I don’t entirely understand how it addresses what I’m speaking of.

My problem is figuring out how I can access data in Atlas using Realm, and how I can, if it is possible, maintain a single code base for my app model.

For example, my app model has a class called Tag, which I use in my desktop app to map to stuff in a the tags collection. My understanding is that in Android with Realm, I’d have to have a different code base because it forces you to use elements of the API to be able to do crud operations normally, such as RealmObject and various annotations.

You can create two database in single altas cluster by creating two users in altas cluster please watch video

I watched it, but I’m not seeing how doing this helps me. I’m sorry but could offer further clarification?

First create Two users

Username same as database name
User should provide readWrite preimssion

Go to collection on Altas

Press on + icon and create database same name of username created