Datastore

A simple in-memory key-value datastore for sharing data within the n8n instance.

Overview

This node implements a simple in-memory key-value datastore within the n8n instance. It allows users to store, retrieve, and clear data by unique keys during workflow execution. The data is kept in memory and shared across executions of this node, making it useful for temporary data persistence or sharing information between different parts of a workflow.

Common scenarios include:

  • Caching intermediate results to avoid repeated expensive computations.
  • Sharing state or flags between different branches or executions of workflows.
  • Storing configuration or small datasets temporarily during workflow runs.

For example, you could use the "Set" operation to save a list of user IDs retrieved from an API, then later use the "Get" operation to fetch that list for further processing without calling the API again.

Properties

Name Meaning
Key Name The unique key under which the data will be stored, retrieved, or cleared.
Output for Set/Clear Defines what the node outputs after a Set or Clear operation. Options:
                  - Pass Through: Outputs the same input data unchanged.                                                 
                  - Output Key: Outputs only status, operation, and key.                                                 
                  - Output Value: Outputs status, operation, and the saved or cleared value.                             
                  - Output Key-Value: Outputs only the key-value pair.                                                    |

Output

The node outputs JSON objects with fields depending on the operation and output option selected:

  • Set Operation:

    • If multiple items are set with the same key and JSON datatype, outputs can include:
      • Status with success, operation name, key, and item count.
      • The saved array value.
      • Only the key-value pair.
      • Or pass through original input items.
    • For single items, outputs include success status, operation, key, and optionally the saved value or key-value pair.
  • Get Operation:

    • Outputs the key, the stored value, and a boolean found indicating if the key existed.
    • If the stored value is an array, each element is output as a separate item.
  • Clear Operation:

    • Outputs success status, operation, key, and whether the key was cleared.
    • Optionally includes the cleared value if requested.
  • Clear All Operation:

    • Outputs success status and operation.

If binary data were supported (not indicated here), it would be summarized accordingly, but this node handles only JSON-compatible data.

Dependencies

  • No external services or APIs are required.
  • The node uses an internal static Map object to store data in memory.
  • No special credentials or environment variables are needed.

Troubleshooting

  • Missing Key Name: Operations "set", "get", and "clear" require a non-empty key name. Omitting it will cause an error.
  • Invalid JSON Input: When setting values with JSON datatype, invalid JSON strings will cause errors specifying the problematic item index.
  • Unknown Data Type: Only "string" and "json" datatypes are supported for values; others will trigger errors.
  • Data Persistence: Since the datastore is in-memory, all data is lost when the n8n instance restarts.
  • Multiple Items with Different Keys or Types: When setting multiple items at once, all must share the same key and datatype to be processed as a batch; otherwise, they are handled individually.

Links and References

Discussion