I got an error while opening another user's realm

About

I’m developing ios app with Realm Cloud.
My app has multiple realm; one Common realm and many Private(per-user) realm.
I logged in realm server with specific user and tried to open another user’s Private realm following this method.

Code

// already logged in
let userIdentity = "fjwe3akj4d308fj2okljt439fwe127ahkf" // target user's identity
let realmURL = URL(string: "realms://myapp.us1.cloud.realm.io/\(userIdentity)/PrivateSyncRealm")!
let configPrivate = currentUser.configuration(realmURL: realmURL, fullSynchronization: true, enableSSLValidation: true, urlPrefix: nil)

Realm.asyncOpen(configuration: configPrivate) { realm, error in
    if let realm = realm {
        print("success")
        let user = realm.objects(User.self).filter(String(format: "syncuserid == '%@'", userIdentity))
        print(user[0])
        
    } else if let error = error {
        print("failed")
        print(error)
    }
    
}

Actual Results

I got an error.

failed

**Domain=io.realm.unknown Code=89 "Operation canceled" 
UserInfo={Category=realm.basic_system, 
NSLocalizedDescription=Operation canceled, Error Code=89}**

I think that permission of the user could be a factor? (but don’t know how to modify)

Question

How to solve this error and get data from Private realm of another user.

Infomation

target realm: Sync - Full
logs: HTTP response: ◯◯◯◯◯◯ {"type":"https://docs.realm.io/server/troubleshoot/errors#access-denied","title":"The path is invalid or current user has no access.","status":403,"code":614}

Lets back up a step. Are you using ‘legacy’ Realm or MongoDB Realm? It looks like it’s kinda both and if so, that’s not going to work.

The linked question and the code provided by @Ian_Ward is for MongoDB Realm and involves partitions which don’t exist in ‘legacy’ Realm. But this code

let configPrivate = currentUser.configuration(realmURL: realmURL, fullSynchronization: true, enableSSLValidation: true, urlPrefix: nil)

is how legacy Realm would connect.

If you’re going with MongoDB Realm (which you should be at this point). Go through the getting started guide Sync Data section to see how to connect up to MongoDB Realm and how to utilize partitions.

Once you do that, the code provided by Ian will make a lot more sense.

I may just be not looking at the question correctly.

Just a moment ago, I knew that Realm is different from MongoDB Realm.
I’m using legacy Realm Cloud, so I’d like to user it for the time being.

@Shi_Miya Are you trying to open a realm that is private for the user doing the opening? If so, you can use the tilda - ~ - to automatically fill this in like so:
realms://myapp.us1.cloud.realm.io/~/PrivateSyncRealm

If you are trying to open another user’s realm then you need to grant permission to the user performing the open - see here:
https://docs.realm.io/sync/using-synced-realms/access-control/path-level-permissions

1 Like

Thank you for your explanation.

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