Anonymous User in Realm Mobile Platform

Anonymous user in Realm Mobile Platform

Can I connect to a remote Realm without having to login?

No, you always need to be authenticated.

Is there a method for getting an anonymous User so that anyone can connect to the remote Realm?

Yes, via SyncCredentials.anonymous().

realm mobile platform, how to connect while offline?

After you successfully log in (or register) the user it's cached in the device's keychain and you can retrieve it via currentUser property or alternatively if your app supports multiple users all even when you're offline.

Please note if you call logout on a user then it will be removed from the keychain and you will have to be online and log in again.

Share realm between different users on Realm Object Server?

In general, you can connect to a Realm file at a virtual path. They must be always absolute, so begin with a leading slash / and never carry a file suffix. Realms at a file name with two leading underscores are considered internal state of the Realm Object Server and have special meaning.

If a path is prefixed by /~/ (like the home directory), the ~ will be expanded by the ID of the user, who is exclusively privileged to create, read and write to Realm files placed within this virtual directory.

If there is no such prefix (e.g. /global), then this is a global Realm. Global Realms may only be created by admin users, but are by default readable by everyone.

Unfortunately we don't offer a direct client-side API yet to manage permissions. But you can access the admin realm living at /__admin with the browser and find the permissions for the given file. Permission where the user is set are specific to this user. The Permission where no user is set are the default permissions. They apply for all users who don't have specific permissions configured. The owner has full access by default by an explicit Permission entry.

Realm Mobile Platform Architecture - Thousands of realms VS big realm files

Disclaimer: I'm not an official source!

RMP 1.x required manually managing what you want to sync by building the right sync configuration and storing it in a different Realm, as you had to sync the whole Realm file to query from it. This makes either of the above solutions somewhat tricky.


With the official release of Realm Mobile Platform 2.0 (2017-10-17), this should actually be quite simple.

From the docs:

Part of Realm Platform 2.0, we are launching a preview of partial
synchronization. This is a new and exciting capability where client
applications can dynamically request data from Realm Object Server by
registering queries.

This is a major change in how application
developers can use Realm in their apps. Previously, applications would
need to segment their data into multiple Realms to control which data
is synced at a given time. Now this can be done entirely in a single
Realm!

The magic is that:

  • SyncConfiguration has a partialRealm() or partial (or similarly named) property

    Realm.open({
    sync: {
    url: `realm://${URL}/tickers`,
    user: user,
    partial: true
    },
    schema: [TickerSchema],
    })
  • Realm has a subscribeToObjects() method that can receive a query definition (the Java preview api also uses the Javascript query language at the time of writing in 4.0.0):

    realm.subscribeToObjects('Ticker', 'price > ' + price)

In JS world it returns a promise so you can just do .then((results, error) => {,

in Obj-C and Java you seem to have to use a callback that will receive the RealmResults that you can subscribe to with a change listener.

OBJECTIVE-C
- (void)subscribeToObjects:(nonnull Class)type
where:(nonnull NSString *)query
callback:(nonnull RLMPartialSyncFetchCallback)callback;
SWIFT
func subscribe(toObjects type: AnyClass, where query: String, callback: @escaping RLMPartialSyncFetchCallback)

JAVA
void subscribeToObjects(Class<E> clazz, String query, Realm.PartialSyncCallback<E> callback)

The callback returns a Results, and you can add the notification block / change listener to that. In Java, you should make sure a reference is stored to the RealmResults.

Server replication for Realm Mobile Platform

As you know, we are currently in beta. There are a number of features that we haven't been able to ship yet, but that are most definitely in the works and/or on our radar. Manual (snapshot) and continuous backup (live redundancy) is definitely part of this.

As you imagine, I can't commit to a firm timeline, as we have a fairly limited development team, and we're still going through all the feedback we've received since launch in order to figure out our priorities.

If you want, you can submit this as an issue in our bugtracker: https://github.com/realm/realm-mobile-platform/issues



Related Topics



Leave a reply



Submit