Tutorial

Time to Complete: 15 minutes | Difficulty: Beginner friendly
This guide will get you up and running with Coreflux MQTT Broker and MongoDB in under 15 minutes using Docker.

Quick Overview
https://youtu.be/h554ybSD_oc
Before you start, make sure you have:
Need Help? Throughout this tutorial, you can get instant assistance at docs.coreflux.org using the Ask AI feature. Simply describe what you are trying to do, and get personalized guidance on LoT syntax, troubleshooting, and best practices.
Create a file called docker-compose.yml and paste the following:
services:
mongodb:
image: mongo:latest
container_name: mongodb
ports:
- "27017:27017"
environment:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: coreflux_password
MONGO_INITDB_DATABASE: iot_data
volumes:
- mongodb_data:/data/db
networks:
- iot_network
coreflux:
image: coreflux/coreflux-mqtt-broker:latest
container_name: coreflux
ports:
- "1883:1883"
- "1884:1884"
- "5000:5000"
- "443:443"
depends_on:
- mongodb
networks:
- iot_network
volumes:
mongodb_data:
networks:
iot_network:
driver: bridge
Start with:
docker-compose up -d
Stop with:
docker-compose down

Tip: You can set the credentials and see connection status in the bottom left bar of VS Code.
Not familiar with LoT syntax? Visit docs.coreflux.org and use the Ask AI feature for instant explanations and examples.
DEFINE ACTION GenerateData
ON EVERY 10 SECONDS DO
PUBLISH TOPIC "sensors/temp" WITH RANDOM BETWEEN 20 AND 30
DEFINE MODEL SensorData WITH TOPIC "processed/sensor/data"
ADD "temperature" WITH TOPIC "sensors/temp" AS TRIGGER
ADD "temp_fahrenheit" WITH (temperature * 9/5 + 32)
ADD "timestamp" WITH TIMESTAMP "UTC"
DEFINE ROUTE mongo_route WITH TYPE MONGODB
ADD MONGODB_CONFIG
WITH CONNECTION_STRING "mongodb://admin:coreflux_password@mongodb:27017/iot_data?authSource=admin"
WITH DATABASE "iot_data"
Add this to the end of your Model:
STORE IN "mongo_route"
WITH TABLE "MachineProductionData"
Complete Model with storage:
DEFINE MODEL SensorData WITH TOPIC "processed/sensor/data"
ADD "temperature" WITH TOPIC "sensors/temp" AS TRIGGER
ADD "temp_fahrenheit" WITH (temperature * 9/5 + 32)
ADD "timestamp" WITH TIMESTAMP "UTC"
STORE IN "mongo_route"
WITH TABLE "MachineProductionData"
Use MQTT Explorer to connect and see live data on topics:

Connect with MongoDB Compass using:
mongodb://admin:coreflux_password@localhost:27017
Verify data in the MachineProductionData collection.

Cannot connect to MQTT broker?
Cannot connect to MongoDB?
Data not showing in MongoDB?
Now that you have a working pipeline, you can: