Is it possible to reset the default realm without creating a new instance?


#1

Is there a way to reset the default synced realm when using query based sync? The only way I found now is to create a new realm instance, which is a pain as I have to do this often during development. Is there another way?


#2

@Sipe Does deleteAll() work for you?

try! realm.write {
    realm.deleteAll()
}

#3

Thanks for the quick reply! My question was rather if there was a way I the admin GUI as I didn’t want to change the apps code to reset the server.

However, it turned out query based sync wasn’t the right choice for my use case. So I went back to fully synced realms and new I can just delete the users realm to start over, so no problem.


#4

This does not work for partially synced realms. It just throws an exception. Is there another way to clear the default realm? Or do I need to create a new server instance?


#5

@Sipe It should work. Please file a ticket with details and code snippet and steps to repro and we will investigate.


#6

I think this is by design. The exception thrown is pretty clear.

java.lang.IllegalStateException: This API is not supported by partially synchronized Realms. Either unsubscribe using 'Realm.unsubscribeAsync()' or delete the objects using a query and 'RealmResults.deleteAllFromRealm()

I guess I could probably do an async query to delete everything. Still, it is pretty annoying to have to do this in the app itself as I don’t want the code in there in production.

Right now I am testing moving from a local to synced realm and I pretty much want to reset the content before try the migration. The easiest way I found is to create a new instance, but then I have to reconfigure login, change sync url etc. It would be nice if there was an easier way, ideally from realm studio.

EDIT: Just found an easier way. In realm studio you can select one item… scroll all the way to the bottom and and mark all items. This is a lot easier than what I tried before. Still, scrolling a table with 15000+ items in it is no fun :wink:


#7

@Sipe I thought your were using Swift… Probably best to clearly state the exception and SDK you are using from the beginning.

in Java this does a clear of the available elements (within the subscription) for every table in the schema
TBL(nativeTablePtr)->where().find_all().clear(RemoveMode::unordered);


#8

Use this:
r.where(PartialSyncObjectA.class).findAll().deleteAllFromRealm();

Yes we’d like to update deleteAll in the future, see the test here:


#9

Sorry about that, I am using swift for the iOS app and Kotlin for the Android app. The question was if there was a generic way though. It would be a lot easier if I could do this from realm studio instead of having to do it in both the iOS and Android app.

I guess creating my own web based admin ui wouldn’t be a bad idea? How do other customers manage this? Do they tend to do it directly from the clients during development?


#10

Perfect! Thanks I’ll try that.


#11

Not sure this works as expected either. I tried deleting all objects via a query as you suggested, but the cloud instance got corrupted and now I can’t sign in.

I guess that the deleted objects are not actually deleted from the server? It is just the changes? That would mean that I won’t get back to a clean object server simply by deleting all objects, right?

I am copying back items using the same object ids as those that are deleted so I guess this could be the cause of the corruption in this case.

Internal sync error (path: /__admin). Message: End of input, category: realm.network, code: 1, name: Error.
Yesterday at 8:21 AM
Internal sync error (path: /__revocation). Message: End of input, category: realm.network, code: 1, name: Error.
Yesterday at 8:21 AM
Internal sync error (path: /__wildcardpermissions). Message: End of input, category: realm.network, code: 1, name: Error.
Yesterday at 8:21 AM
Internal sync error (path: /__configuration). Message: End of input, category: realm.network, code: 1, name: Error.
Yesterday at 8:21 AM
Internal sync error (path: /__perm). Message: End of input, category: realm.network, code: 1, name: Error.
Yesterday at 8:21 AM
Internal sync error (path: /__perm). Message: Connection refused, category: realm.basic_system, code: 111, name: Error.
Yesterday at 8:21 AM
Internal sync error (path: /__configuration). Message: Connection refused, category: realm.basic_system, code: 111, name: Error.
Yesterday at 8:21 AM
Internal sync error (path: /__wildcardpermissions). Message: Connection refused, category: realm.basic_system, code: 111, name: Error.

#12

@Sipe Eesh - please open a support ticket on this and we will investigate.


#13

I had to create a new instance and haven’t seen the issue since. If I see it again I will open up a ticket. I think it was related to reusing old database indexes, which I did using the old local realm, but I should not do now.

As for resetting the realm from the client, it is not so easy.

Realm.where(PartialSyncObjectA.class).findAll() only returns the elements the currently signed in user has access too. If I want to reset the realm cloud instance I would have to log in using an admin user to do a query that would match everything and then I would have to use the Realm.where(PartialSyncObject.class).findAll() for each and every class in my schema. Currently, I guess the easiest way is to create a new realm instance or mark and scroll through everything in Realm Studio.