The MONGODB route stores MQTT messages as documents in MongoDB collections. It uses the CLEAN query format for simplified JSON syntax and supports flexible schemas for IoT data.
MongoDB is ideal for IoT data with varying schemas. Store sensor readings, events, and logs without defining rigid table structures upfront.
DEFINE ROUTE SensorStorage WITH TYPE MONGODB ADD MONGODB_CONFIG WITH CONNECTION_STRING "mongodb://iot_user:[email protected]:27017/iot?authSource=admin" WITH DATABASE "iot" ADD EVENT StoreReading WITH SOURCE_TOPIC "sensors/+/reading" WITH DESTINATION_TOPIC "db/mongo/status" WITH QUERY "CLEAN:{collection: readings, document: {timestamp: {timestamp}, topic: {source_topic}, data: {value.json}}}"
Create structured documents with specific fields:
Copy
Ask AI
DEFINE ROUTE StructuredStorage WITH TYPE MONGODB ADD MONGODB_CONFIG WITH CONNECTION_STRING "mongodb://user:[email protected]:27017/iot" WITH DATABASE "iot" ADD EVENT StoreSensor WITH SOURCE_TOPIC "sensors/+/data" WITH QUERY "CLEAN:{collection: sensor_data, document: {sensor_id: {sensor_id}, temperature: {value.json.temperature}, humidity: {value.json.humidity}, recorded_at: {timestamp}}}"