Join us at MongoDB.local London on 7 May to unlock new possibilities for your data. Use WEB50 to save 50%.
Register now >
Docs Menu
Docs Home
/ /
CRUD

CRUD - Delete - Flutter SDK

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.

Los ejemplos de esta página utilizan dos tipos de objetos, Person y Team.

@RealmModel()
class _Person {
@PrimaryKey()
late ObjectId id;
late String name;
late List<String> hobbies;
}
@RealmModel()
class _Team {
@PrimaryKey()
late ObjectId id;
late String name;
late List<_Person> crew;
late RealmValue eventLog;
}

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 from the database by calling Realm.deleteMany() in a write transaction block.

realm.write(() {
realm.deleteMany([obiWan, quiGon]);
});

Delete all objects of a type in the database with Realm.deleteAll() in a write transaction block.

realm.write(() {
realm.deleteAll<Person>();
});

Volver

Update

En esta página