How do I create and use a realm?

ros

#1

I am busy experimenting with Realm and have a server instance running for sync purposes.

I created some classes with Realm Studio but could not edit them so I deleted the entire realm - yes the default realm. I then created a new realm called ‘default’ and created the classes but am unable to figure out how to connect to it.

I think a simple explanation for how to do this would be useful as all the examples seem to assume an existing default realm on the server - or something.

Can anyone provide a step by step guide to recreating the default realm on a server and the steps required by the client application for connecting to the server and getting a copy of the schema and existing database.

This seems like a relatively simple thing to have to do and yet I can’t seem to find any explanation of how to do this. Hopefully I am just not looking in the right place.

Thanks and apologies in advance if I missed something obvious.


#2

@duncan The /default realm is just a generic starting realm that we generate for you but you can certainly create a bunch of other realms and name them whatever you want. I’d recommend starting with our tutorial here;
https://docs.realm.io/platform/getting-started-1/ios-quick-start/step-1-my-first-realm-app

In it you will see that it creates a realm called /ToDo with this schema:

class Item: Object {
    
    @objc dynamic var itemId: String = UUID().uuidString
    @objc dynamic var body: String = ""
    @objc dynamic var isDone: Bool = false
    @objc dynamic var timestamp: Date = Date()

The schema gets created because the user (by default an admin privileges) opens a realm to that server with that schema.

If you do not want to go through the tutorial step by step you can clone the tutorial here and start playing around:


#3

I have a macOS desktop app that is using realm and it works fine so I am just wanting to see whether it is possible to use the platform to replicate the data to another desktop.

Its not at all obvious how one goes about making the existing realm database sync but I tried using the default realm on a local docker ROS server and it sort of almost worked.

I changes the desktop realm connection configuration to include the URL for the ROS server and then user the user objects realm configuration when opening a Realm within the app - which uses multiple threads.

I tried to start with a clean instance and then batch load data into the desktop app - which currently uses a bunch of Operations - but it seems to hang up on the 4th or 5th operation when calling realm.beginWrite().

The ROS server console output has a mass of what looks like binary data - so much so that Realm Studio crashes when trying to look at the logs.

Just curious as to how robust the Realm object server is ? I am tempted to try using a cloud instance to see if that works.

Can you confirm my use case is a feasible one - the desktop app has < 500k records and is about 5mb in size.


#4

@duncan Yes that’s easily feasible - I’ve loaded over a 100GB into a single realm before

Not sure what you are doing wrong but I would recommend going through the tutorials and building from there. Perhaps it has something to do with your multi-threading - because Realm is single process and each thread opens its own instance of Realm and then is GC’d later. If you don’t release the reference it could use up a lot of memory - take a look here:

https://docs.realm.io/platform/guides/the-realm-data-model