Update & Delete
Modify existing records with partial updates, or remove them permanently.
Update a record
Updates are partial — only the fields you provide are changed. Existing fields not included in the update are preserved.
lib/database.dartDart
final updated = await Koolbase.db
.collection('posts')
.doc('record-uuid-here')
.update({
'title': 'Updated title',
'published': true,
});
// Only 'title' and 'published' changed
// All other fields remain unchanged
print(updated.data['title']); // Updated title
print(updated.data['body']); // original body still here
print(updated.updatedAt); // new timestampPartial updates
Updates merge with the existing record. To remove a field, you would need to set it to
null explicitly. There is no unset operation — the JSONB data column is merged on update.Delete a record
Permanently removes a record. This action cannot be undone.
lib/database.dartDart
await Koolbase.db
.collection('posts')
.doc('record-uuid-here')
.delete();Access rules on write and delete
Write and delete operations are subject to the collection's rules. The three possible values:
authenticatedAny logged-in user can update or delete any record
ownerOnly the record's creator (created_by) can update or delete it
Owner check
When the write or delete rule is
owner, the server checks that record.created_by == current_user.id. If not, a 403 Forbidden error is returned. Make sure the user is logged in before attempting to update or delete owned records.Error handling
lib/database.dartDart
try {
await Koolbase.db
.collection('posts')
.doc(postId)
.delete();
} on KoolbaseException catch (e) {
switch (e.code) {
case 'not_found':
showError('Post not found');
case 'permission_denied':
showError('You do not have permission to delete this post');
default:
showError('Failed to delete: ${e.message}');
}
}