You can choose to delete a single object, multiple objects, or all objects from the database. After you delete an object, you can no longer access or modify it. If you try to use a deleted object, the SDK throws an error.
Deleting objects from the database does not delete the realm file or affect the schema. It only deletes the object instance from the database. If you want to delete the realm file itself, refer to Delete a Realm File - Flutter SDK.
Borrar objetos
Los ejemplos de esta página utilizan dos tipos de objetos, Person y Team.
() class _Person { () late ObjectId id; late String name; late List<String> hobbies; } () class _Team { () late ObjectId id; late String name; late List<_Person> crew; late RealmValue eventLog; }
Delete a Single Object
Eliminar un objeto de la base de datos llamando Reino.eliminar() en un bloque de transacción de escritura.
realm.write(() { realm.delete(obiWan); });
Delete Multiple Objects
Delete multiple objects from the database by calling Realm.deleteMany() in a write transaction block.
realm.write(() { realm.deleteMany([obiWan, quiGon]); });
Eliminar todos los objetos de un tipo
Delete all objects of a type in the database with Realm.deleteAll() in a write transaction block.
realm.write(() { realm.deleteAll<Person>(); });