New
EMQX Enterprise 6.3 (LTS) Release Strengthens Security for Mission-Critical MQTT Deployments →

EMQX MongoDB Integration

Stream MQTT data to MongoDB

Collect sensor readings, device status, and asset locations with EMQX, then store them in MongoDB for application queries and dashboards.

Overview

Store IoT data your applications can use

EMQX connects your devices and prepares their messages. MongoDB stores the resulting documents for your applications to query.

Keep readings and context together

Store sensor readings alongside device attributes and metadata. MongoDB’s flexible documents accommodate different device structures as your fleet evolves.

Separate ingestion from queries

EMQX handles MQTT connections and message processing while MongoDB serves application queries. Size each layer around your traffic and data access needs.

Buffer during interruptions

Buffer outgoing requests in EMQX and retry recoverable errors. Set buffer capacity and request expiry for your workload, and monitor failed and dropped requests.

Architecture

From MQTT messages to MongoDB documents

Devices publish MQTT messages to EMQX. SQL rules select and transform the data, and a MongoDB sink inserts the results into a collection for your applications to query.

Capabilities

Shape MQTT data for MongoDB

Control which messages you store, how their fields are mapped, and how delivery is monitored.

Map fields to documents

Map rule results into a MongoDB document with the sink’s payload template. Keep field names and types consistent for queries across devices, including nested objects and arrays.

Filter and transform with SQL

Match MQTT topics, select payload fields, filter unwanted messages, and transform values before writing to MongoDB.

Choose your MongoDB connection

Connect to a standalone instance, replica set, or sharded cluster. Match the connector mode to your MongoDB deployment, and enable TLS to encrypt the database connection.

Query device history

Use MongoDB queries and aggregation pipelines to investigate readings and events. Create indexes in MongoDB to support your application’s access patterns.

Work with location data

Store asset or vehicle positions as GeoJSON, then use MongoDB geospatial indexes for proximity and area-based searches.

Monitor delivery

Track successful, failed, and dropped requests in the EMQX Dashboard. Use these metrics to investigate delivery problems and tune the pipeline.

How it works

From MQTT to MongoDB in three steps

You need EMQX Enterprise, network access to MongoDB, and credentials that can write to the target database and collection.

  1. 1

    Connect EMQX to MongoDB

    Create a MongoDB connector in the EMQX Dashboard. Select the deployment mode, enter connection details and credentials, then test connectivity.

  2. 2

    Define the rule and sink

    Create a SQL rule to match MQTT topics and prepare fields. Attach a MongoDB sink, then set its collection and payload template.

  3. 3

    Publish and verify

    Connect an MQTT client and publish a test message. Query MongoDB to confirm the document’s fields and types before sending production traffic.

Resources

Dive deeper into EMQX & MongoDB

FAQ

Frequently asked questions

Build your MongoDB ingestion pipeline

Plan your MQTT data flow, document structure, and MongoDB deployment with an EMQX expert.