Skip to main content

Delete All Objects of a Type

To delete all objects of a type from a realm:

  1. Open a write transaction with realm.write() or realm.writeBlocking().

  2. Query the transaction's mutable realm with realm.query(). Specify the object type as a type parameter passed to query().

  3. Delete the set of RealmResults returned by the query with realmResults.delete().

realm.write {
// fetch all frogs from the realm
val frogs: RealmResults<Frog> = this.query<Frog>().find()
// call delete on the results of a query to delete those objects permanently
frogs.delete()
}
note

You can only delete objects in a realm within a write transaction.