Data Storage Integration
Data storage routes enable automatic persistence of MQTT messages to databases and files. Store sensor data for analytics, create historical archives, aggregate logs, and build time-series datasets—all configured through LoT syntax.Supported Databases
PostgreSQL
Open-source relational database for structured data storage.
MySQL
Popular relational database with wide ecosystem support.
MariaDB
MySQL-compatible database with enhanced features.
SQL Server
Microsoft SQL Server for enterprise environments.
MongoDB
Document database for flexible JSON storage.
OpenSearch
Real-time analytics, search, and visualization.
CrateDB
Distributed SQL optimized for time-series data.
Snowflake
Cloud data warehouse for large-scale analytics.
File Storage
CSV and JSON file storage for simple persistence.
Database Comparison
| Database | Type | Best For | Query Format |
|---|---|---|---|
| PostgreSQL | Relational | Structured data, complex queries | SQL |
| MySQL | Relational | Web applications, general purpose | SQL |
| MariaDB | Relational | MySQL compatibility with extras | SQL |
| SQL Server | Relational | Enterprise, Windows environments | SQL |
| MongoDB | Document | Flexible schemas, JSON data | CLEAN |
| OpenSearch | Search/Analytics | Full-text search, dashboards | CLEAN |
| CrateDB | Time-Series | High-volume sensor data | SQL |
| Snowflake | Cloud Warehouse | Large-scale analytics | SQL |
| File Storage | File | Simple logging, backups | CLEAN |
SQL databases use standard SQL queries. CLEAN is a simplified document-style syntax used by non-relational databases and file storage — see Query Formats below for details.
How to Build a Data Storage Route
A data storage route needs two things: a connection to your database and at least one rule for what to store. You define the connection once, then add events that listen for MQTT messages and run queries — or use a model withSTORE IN to save data automatically without writing queries at all.
Quick Example
This complete route connects to a PostgreSQL database and automatically stores every sensor reading that arrives onsensors/+/reading:
Step 1: Define the Route Connection
Every data storage route starts with a connection configuration. Define the route type and provide the connection details for your database:Each database type has its own config block (
SQL_CONFIG, MONGODB_CONFIG, OPENSEARCH_CONFIG, etc.). See the specific database page for exact parameters.Step 2: Store Data
There are two ways to write data into your database. Choose the approach that fits your use case:- With Models (STORE IN)
- With Events (INSERT)
The 2. Define the route the model stores into:3. Publish the model from an action:Every
STORE IN approach ties a model directly to a database route. Every time an action publishes this model, the record is automatically inserted into the specified table — no EVENT or query needed.1. Define a model with STORE IN:PUBLISH MODEL call automatically inserts a row into the production_counts table with all the model fields as columns.Step 3: Read Data (SELECT)
EVENTs also support SELECT queries to read data back from the database. Publish a message to the event’sSOURCE_TOPIC with your query parameters, and the result is published to DESTINATION_TOPIC:
factory/production/latest_count_from_db, where your actions or external clients can consume it.
Common Query Placeholders
These placeholders work across all database routes:| Placeholder | Description |
|---|---|
{payload} | Raw MQTT payload (useful in SELECT queries as a parameter) |
{value} | Full MQTT payload as string |
{value.json} | Parsed JSON payload |
{value.json.field} | Specific field from JSON |
{timestamp} | Message timestamp |
{source_topic} | Original MQTT topic |
{field} | Field extracted from topic path |
Extracting Fields from Topics
For topicsensors/temp001/reading, use these placeholders:
| Placeholder | Value |
|---|---|
{source_topic} | sensors/temp001/reading |
{sensor_id} | temp001 (position 2 in topic) |
Query Formats
SQL Format
For relational databases (PostgreSQL, MySQL, MariaDB, SQL Server, CrateDB, Snowflake):CLEAN Format
For document databases and search engines (MongoDB, OpenSearch, File Storage):Common EVENT Parameters
Trigger & Routing
Trigger & Routing
MQTT topic pattern that triggers the query. For INSERT operations, incoming message data is used to populate placeholders. For SELECT operations, the payload can be used as a query parameter via
{payload}.MQTT topic to publish query results. Required for SELECT queries so the result can be consumed by actions or external clients. Optional for INSERT queries (publishes operation status).
Query
Query
SQL statement or CLEAN format query with placeholders. Supports both write operations (
INSERT INTO ...) and read operations (SELECT ... FROM ...).Best Practices
Use SSL and Certificates in Production
Use SSL and Certificates in Production
Always enable SSL for database connections. Most database routes support SSL configuration through the config block:When using certificate-based authentication, store certificate passphrases as encrypted secrets rather than in plain text. See Environment Variables and Secrets for details.
Secure Your Credentials
Secure Your Credentials
Never hardcode passwords or API keys in route definitions. Use
GET SECRET for sensitive values and GET ENV for non-sensitive configuration like hostnames and ports. Create dedicated database users with minimal permissions for each route.See Environment Variables and Secrets for full setup and deployment instructions.Monitor Database Size
Monitor Database Size
Implement data retention policies:
- Index lifecycle management
- Time-based partitioning
- Automatic cleanup jobs
Use STORE IN for Automatic Persistence
Use STORE IN for Automatic Persistence
When your data has a consistent schema, use
STORE IN on a model to automatically insert records every time the model is published. This eliminates the need to write INSERT queries manually:Use Connection Pooling
Use Connection Pooling
For high-throughput scenarios, configure connection pools where supported.
Next Steps
Choose the database that matches your requirements:PostgreSQL
Start with the most popular open-source database.
MongoDB
Store flexible JSON documents.

