2

I have a function in my app where the user reset the account whenever he/she desires to do so and I want to delete the whole realm local database and start over with creating a new one after completed process of deleting it.

This is not for migration but rather wipe out the whole database and start over as if the app was deleted and installed again.

Is there any way to do this, I can't seem to find information on this

My code is written in React Native so this is RealmJS

1
  • Classic Realm or MongoDB Realm (sync)? Commented Feb 10, 2021 at 19:38

2 Answers 2

0

I don't know if this can help you : https://stackoverflow.com/a/26244843/9231356

let realm = try! Realm()
try! realm.write {
    realm.deleteAll()
}
Sign up to request clarification or add additional context in comments.

4 Comments

Good answer. Just a caveat that this code will not work if Realm has been 'talked to' before this code. e.g. as soon as you app does anything with Realm, it remembers that connection. Even if you delete the files, it will re-create itself. So, this code needs to run before any connection to realm is made.
So you are saying that this could work if I create a code where the user "Delete Account", the app restarts but this time I run the code above before anything else ?
I forgot to mention that I use an encryption key for the database so I somehow need to delete it while the key (or realm instance for corresponding key) is in memory..
@tompa yes. As long as that code runs before making any other connection to Realm it will work. Otherwise the data will re-populate.
0
  1. Open Device Manager (Android Studio)
  2. Open in Explorer
  3. find data/data/com.YouRNAPP/files/
  4. delete *.realm , *.realm.lock , *.realm.note

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.