Skip to main content

List

Lists all keys in the BadgerDB database, optionally filtered by a key prefix.

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 list operation will use that transaction context.
  • Prefix - (Optional) A prefix to filter keys. Only keys starting with this prefix will be returned. Leave empty to list all keys.

Output

  • Keys - An array of strings containing all keys that match the prefix filter. Returns an empty array if no matching keys are found.

How It Works

The List node iterates through all keys in the database and returns those matching the optional prefix filter.

When executed, the node:

  1. Validates the database ID
  2. Retrieves the optional prefix filter
  3. Creates a read-only view of the database
  4. Iterates through keys using an iterator
  5. Collects keys that match the prefix (or all keys if no prefix specified)
  6. Returns the array of matching keys

Examples

Example 1: List All Keys

Get all keys in the database:

List
Database Id: {{db_id}}
Prefix: (empty)

Output:
Keys: [
"user:1001",
"user:1002",
"session:abc123",
"cache:api:weather",
"config:app:version"
]

Example 2: List User Keys

Get all user-related keys:

List
Database Id: {{db_id}}
Prefix: user:

Output:
Keys: [
"user:1001",
"user:1002",
"user:1003"
]

Example 3: List Session Keys

Find all active sessions:

List
Database Id: {{db_id}}
Prefix: session:

Output:
Keys: [
"session:abc123",
"session:def456",
"session:ghi789"
]

Example 4: List and Process Keys

List keys and perform operations on each:

1. List Cache Keys
Database Id: {{db_id}}
Prefix: cache:
→ cache_keys

2. For Each {{key}} in {{cache_keys}}:
Get
Database Id: {{db_id}}
Key: {{key}}
→ value

Log: {{key}} = {{value}}

Example 5: List for Bulk Delete

Find and delete all temporary keys:

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

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

Example 6: Hierarchical Prefixes

Use nested prefixes for organization:

List User Settings
Database Id: {{db_id}}
Prefix: user:1001:settings:

Output:
Keys: [
"user:1001:settings:theme",
"user:1001:settings:language",
"user:1001:settings:notifications"
]

Tips for Effective Use

  • Use Descriptive Prefixes - Structure keys hierarchically (e.g., "user🆔", "cache:api:")
  • Colon Separators - Use colons to separate prefix levels for clarity
  • Empty Prefix Lists All - Omit prefix to retrieve all keys in the database
  • Process in Batches - For large result sets, process keys in batches
  • Combine with Get - Use List to find keys, then Get to retrieve values
  • Combine with Delete - Use List for bulk deletion operations
  • Use Consistent Naming - Maintain consistent key naming conventions

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
List (Database Id: {{db_id}})

Empty Result Array

Solution: No keys match the prefix. This is not an error. Verify:

  • The prefix is correct
  • Keys exist with that prefix
  • Keys haven't been deleted or expired
If {{keys}}.length == 0:
Log "No keys found with prefix: {{prefix}}"

Use Cases

Inventory Management

List all product keys:

List
Database Id: {{db_id}}
Prefix: product:
→ product_keys

Session Monitoring

Find all active sessions:

List
Database Id: {{db_id}}
Prefix: session:
→ active_sessions

Log "Active sessions: {{active_sessions.length}}"

Cache Statistics

Count cached items by type:

1. List API Cache
Database Id: {{db_id}}
Prefix: cache:api:
→ api_cache_keys

2. List DB Cache
Database Id: {{db_id}}
Prefix: cache:db:
→ db_cache_keys

Log "API cache entries: {{api_cache_keys.length}}"
Log "DB cache entries: {{db_cache_keys.length}}"

Data Export

List and export specific data:

1. List
Database Id: {{db_id}}
Prefix: report:
→ report_keys

2. For Each {{key}} in {{report_keys}}:
Get
Database Id: {{db_id}}
Key: {{key}}
→ data

Append to Export File: {{data}}

Cleanup Old Data

Find and remove expired data:

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

2. For Each {{key}} in {{job_keys}}:
Get
Database Id: {{db_id}}
Key: {{key}}
→ job_data

If {{job_data.completed}} == true:
Delete
Database Id: {{db_id}}
Key: {{key}}

Key Naming Strategies

Hierarchical Structure

user:1001:profile
user:1001:settings:theme
user:1001:settings:language
user:1002:profile

List with prefix "user:1001:" to get all data for user 1001.

Category-Based

cache:api:endpoint1
cache:api:endpoint2
cache:db:query1
cache:db:query2

List with prefix "cache:api:" to get all API cache entries.

Date-Based

log:2025-12-23:error
log:2025-12-23:warning
log:2025-12-24:error

List with prefix "log:2025-12-23:" to get all logs for a specific date.

Type-Based

session:active:abc123
session:active:def456
session:expired:ghi789

List with prefix "session:active:" to get only active sessions.

Performance Considerations

  • Iterator Efficiency - BadgerDB uses efficient iterators for listing
  • Prefix Filtering - Prefix filtering is optimized and fast
  • Large Result Sets - Listing millions of keys is possible but consider pagination
  • Memory Usage - All matching keys are loaded into memory
  • Key Count - For just counting keys, still need to list them all

Advanced Patterns

Pagination Pattern

Process large key sets in chunks:

1. List All Keys
Database Id: {{db_id}}
Prefix: user:
→ all_user_keys

2. Set batch_size = 100
3. Set offset = 0

4. While offset < {{all_user_keys.length}}:
batch = {{all_user_keys}}.slice({{offset}}, {{offset + batch_size}})

For Each {{key}} in {{batch}}:
Process key...

Set offset = {{offset + batch_size}}

Multi-Level Filtering

List and filter further in code:

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

2. Filter active users:
active_user_keys = {{user_keys}}.filter(key =>
key.includes(':active')
)
  • Get - Retrieves values for the listed keys
  • Delete - Deletes keys found by List
  • Set - Creates keys with proper prefixes
  • Export - Exports all key-value pairs to CSV