NATS KV icon

NATS KV

Interact with NATS JetStream Key-Value Store - manage buckets and keys

Actions8

Overview

This node interacts with the NATS JetStream Key-Value (KV) Store, allowing users to manage KV buckets and keys within those buckets. Specifically for the Key - List operation, it lists keys stored in a specified KV bucket filtered by a pattern.

Common scenarios where this node is beneficial include:

  • Retrieving all or a subset of keys from a KV bucket to inspect or process stored data.
  • Filtering keys based on naming patterns to selectively operate on related keys.
  • Integrating with workflows that require dynamic access to configuration or cached data stored in NATS KV.

Practical example:

  • You have a KV bucket named app-config storing various configuration keys like config.db, config.api, and user.settings. Using the "List" operation with the key pattern config.* will return only keys starting with config. for further processing.

Properties

Name Meaning
Bucket Name The name of the KV bucket to operate on. Must contain only letters, numbers, underscores, and hyphens (no spaces or dots). Example: user-preferences, app-config, cache-data. This property is required.
Key Pattern Pattern to filter keys within the bucket. Use > to list all keys, or patterns like config.* to filter keys starting with config., or *.settings to filter keys ending with .settings. This property is required.

Output

The output contains a JSON array where each item corresponds to a key matching the provided pattern in the specified bucket. Each JSON object typically includes details about the key such as its name and possibly associated metadata or value depending on the underlying implementation of the key listing operation.

If the node supports binary data output for keys (not explicitly shown in the provided code), it would represent the binary content of the key's value.

Dependencies

  • Requires a connection to a NATS JetStream server with access to the KV store.
  • Needs an API authentication credential configured in n8n to connect securely to the NATS server.
  • Uses bundled NATS client libraries and utility modules for connection management and operations.

Troubleshooting

  • Invalid Bucket Name: Bucket names must only contain letters, numbers, underscores, and hyphens. Spaces or dots are not allowed. If you get an error about invalid bucket names, verify the bucket name format.
  • Unknown Operation or Resource: Errors indicating unknown operations or resources suggest a misconfiguration in the node parameters. Ensure the resource is set to "Key" and operation to "List".
  • Connection Issues: Failure to connect to the NATS server may occur if credentials are incorrect or the server is unreachable. Verify network connectivity and credential correctness.
  • Empty Results: If no keys are returned, check the key pattern used. Using > lists all keys; other patterns must match existing keys.
  • Continue On Fail: If enabled, the node will continue processing subsequent items even if one fails, collecting errors in the output. Otherwise, execution stops at the first error.

Links and References

Discussion