Overview
This node provides a simple key-value store interface backed by a MongoDB collection. It allows users to either retrieve (get) or store (set) values associated with keys in a MongoDB database. This is useful for scenarios where you want to persist small pieces of data between workflow executions, such as caching results, storing configuration parameters, or sharing state across different parts of an automation.
Practical examples:
- Caching API responses to reduce redundant calls.
- Storing user preferences or tokens securely.
- Maintaining counters or flags that influence workflow logic.
Properties
| Name | Meaning |
|---|---|
| Action | Choose the operation: Get to retrieve a value by key, or Set to store/update a value for a key. |
| Key Name or ID | Select an existing key from the list or specify a new key name using an expression. |
| New Key Name | When setting a value, specify the new key name to create or update. |
| Value | The JSON value to store when performing the Set action. |
| Default Value | The JSON value to return if the specified key does not exist when performing the Get action. |
Output
The node outputs a JSON object with a single field result containing the value associated with the specified key.
For the
Getaction:- If the key exists,
resultcontains the stored value. - If the key does not exist,
resultcontains the provided default value (if any).
- If the key exists,
For the
Setaction:resultcontains the value that was stored.
No binary data output is produced by this node.
Example output JSON for a Get action:
{
"result": {
"someKeyData": "value"
}
}
Dependencies
- Requires access to a MongoDB database.
- Needs credentials providing a valid MongoDB connection string.
- The node interacts with a specific MongoDB database named
n8n-kvand collectionkv-store. - Proper permissions to read and write documents in the
kv-storecollection are necessary.
Troubleshooting
- Connection errors: Ensure the MongoDB connection string credential is correctly configured and the database is accessible from the n8n environment.
- Missing keys on Get: If a key does not exist, the node returns the specified default value. If no default is set, the result will be empty or null.
- Invalid JSON input for Value or Default Value: Make sure the JSON entered in these fields is well-formed; otherwise, the node may throw parsing errors.
- Permission issues: Verify that the MongoDB user has read/write access to the
n8n-kv.kv-storecollection. - Empty key names: Setting or getting with an empty key may lead to unexpected behavior; always provide a valid key.