Skip to main content

Delete

Removes a key-value pair from the BadgerDB database.

Common Properties

  • Name - The custom name of the node.
  • Color - The custom color of the node.
  • Delay Before (sec) - Waits in seconds before executing the node.
  • Delay After (sec) - Waits in seconds after executing node.
  • Continue On Error - Automation will continue regardless of any error. The default value is false.
info

If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.

Inputs

  • Database Id - The unique identifier of the database, as returned by the Open node.
  • Transaction Id - (Optional) The transaction ID from Start Transaction node. If provided, the delete operation will be performed within that transaction context.
  • Key - The key to delete from the database.

How It Works

The Delete node removes a key-value pair from the database. Once deleted, the key will no longer exist and attempts to retrieve it will return a "key not found" error.

When executed, the node:

  1. Validates the database ID and key
  2. Creates or uses an existing transaction
  3. Deletes the key from the database
  4. Commits the transaction (if not part of a larger transaction)

Examples

Example 1: Delete Session Token

Remove an expired session:

Delete
Database Id: {{db_id}}
Key: session:abc123

Example 2: Delete Within Transaction

Delete multiple related keys atomically:

1. Start Transaction
Database Id: {{db_id}}
→ txn_id

2. Delete User Profile
Database Id: {{db_id}}
Transaction Id: {{txn_id}}
Key: user:12345:profile

3. Delete User Settings
Database Id: {{db_id}}
Transaction Id: {{txn_id}}
Key: user:12345:settings

4. Delete User Sessions
Database Id: {{db_id}}
Transaction Id: {{txn_id}}
Key: user:12345:sessions

5. Commit Transaction
Transaction Id: {{txn_id}}

Example 3: Clear Cache Entry

Remove a cached value:

Delete
Database Id: {{db_id}}
Key: cache:api:weather:london

Example 4: Cleanup Old Data

Delete expired temporary data:

For Each key in {{expired_keys}}:
Delete
Database Id: {{db_id}}
Key: {{key}}

Example 5: Remove Configuration

Delete a feature flag:

Delete
Database Id: {{db_id}}
Key: feature:beta_program

Tips for Effective Use

  • Check Before Delete - Use Get to verify a key exists before deleting if needed
  • Use Transactions for Multiple Deletes - Delete related keys atomically to maintain consistency
  • Deleting Non-Existent Keys - Deleting a key that doesn't exist may raise an error; handle this appropriately
  • Use List for Bulk Delete - List keys with a prefix, then delete them in a loop
  • Cleanup Sessions - Regularly delete expired sessions and temporary data
  • Prefix-Based Cleanup - Use key prefixes to organize data for easy bulk deletion

Common Errors and Solutions

Error: "database id cannot be empty"

Solution: Ensure you're passing a valid database ID from the Open node.

Correct:
Open → db_id
Delete (Database Id: {{db_id}})

Error: Key Not Found

Solution: The key doesn't exist in the database. You can either:

  • Ignore the error (it's already deleted)
  • Check if the key exists before deleting
  • Use Continue On Error to proceed regardless
Try:
Delete (Key: user:12345)
Catch:
Log "Key already deleted or doesn't exist"

Error: Transaction Conflict

Solution: Another transaction modified the same key. Options:

  • Retry the delete operation
  • Use proper transaction isolation
  • Ensure transactions are committed promptly

Use Cases

Session Management

Delete user sessions on logout:

Delete
Database Id: {{db_id}}
Key: session:{{session_id}}

Cache Invalidation

Clear cached data when source data changes:

Delete
Database Id: {{db_id}}
Key: cache:user:{{user_id}}

Temporary Data Cleanup

Remove temporary processing data:

1. List
Database Id: {{db_id}}
Prefix: temp:
→ temp_keys

2. For Each {{key}} in {{temp_keys}}:
Delete
Database Id: {{db_id}}
Key: {{key}}

Rate Limit Reset

Manually reset rate limit counters:

Delete
Database Id: {{db_id}}
Key: rate_limit:user:{{user_id}}

Feature Flag Removal

Remove deprecated feature flags:

Delete
Database Id: {{db_id}}
Key: feature:old_feature

Bulk Delete Pattern

Delete multiple keys with a common prefix:

1. List Keys
Database Id: {{db_id}}
Prefix: user:12345:
→ user_keys

2. Start Transaction
Database Id: {{db_id}}
→ txn_id

3. For Each {{key}} in {{user_keys}}:
Delete
Database Id: {{db_id}}
Transaction Id: {{txn_id}}
Key: {{key}}

4. Commit Transaction
Transaction Id: {{txn_id}}

Performance Considerations

  • Delete Performance - BadgerDB handles deletes efficiently
  • Transaction Deletes - Batching deletes in a transaction improves performance
  • Garbage Collection - Deleted data is reclaimed during database compaction
  • Immediate Effect - Deletions are immediately visible (once transaction commits)
  • Storage Reclamation - Space is freed gradually through background compaction

Deletion vs. Expiration

Manual Deletion (Delete Node)

  • Explicit removal of data
  • Immediate effect
  • Full control over when data is removed
  • Use for user actions, cleanup operations

Automatic Expiration (TTL in Set Node)

  • Automatic removal after time period
  • Background cleanup
  • No manual intervention needed
  • Use for sessions, cache, rate limits

Best Practices

  • Use Transactions for Atomic Deletes - Delete related keys together
  • Handle Errors Gracefully - Key not found errors are often acceptable
  • Document Deletion Logic - Comment why keys are being deleted
  • Consider Soft Deletes - For some use cases, mark as deleted instead of removing
  • Cleanup Regularly - Schedule periodic cleanup of temporary data
  • Test Deletion Logic - Ensure critical data isn't accidentally deleted

Data Recovery

Once a key is deleted and the transaction is committed:

  • The data cannot be recovered unless you have a backup
  • Use the Backup node regularly for important databases
  • Test deletion logic carefully before deploying
  • Get - Retrieves values (to check before deleting)
  • Set - Stores values
  • List - Lists keys (useful for bulk deletion)
  • Start Transaction - Starts a transaction for atomic deletes
  • Commit Transaction - Commits transaction changes