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.
EMQX MongoDB Integration
Collect sensor readings, device status, and asset locations with EMQX, then store them in MongoDB for application queries and dashboards.
Overview
EMQX connects your devices and prepares their messages. MongoDB stores the resulting documents for your applications to query.
Store sensor readings alongside device attributes and metadata. MongoDB’s flexible documents accommodate different device structures as your fleet evolves.
EMQX handles MQTT connections and message processing while MongoDB serves application queries. Size each layer around your traffic and data access needs.
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
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.
EMQX Enterprise
MQTT Broker
Capabilities
Control which messages you store, how their fields are mapped, and how delivery is monitored.
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.
Match MQTT topics, select payload fields, filter unwanted messages, and transform values before writing to MongoDB.
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.
Use MongoDB queries and aggregation pipelines to investigate readings and events. Create indexes in MongoDB to support your application’s access patterns.
Store asset or vehicle positions as GeoJSON, then use MongoDB geospatial indexes for proximity and area-based searches.
Track successful, failed, and dropped requests in the EMQX Dashboard. Use these metrics to investigate delivery problems and tune the pipeline.
How it works
You need EMQX Enterprise, network access to MongoDB, and credentials that can write to the target database and collection.
Create a MongoDB connector in the EMQX Dashboard. Select the deployment mode, enter connection details and credentials, then test connectivity.
Create a SQL rule to match MQTT topics and prepare fields. Attach a MongoDB sink, then set its collection and payload template.
Connect an MQTT client and publish a test message. Query MongoDB to confirm the document’s fields and types before sending production traffic.
Resources
FAQ
MongoDB stores telemetry as BSON documents, with support for nested objects, arrays, and varying device metadata. EMQX handles MQTT ingestion and prepares the data before the MongoDB sink inserts it into a collection. The flow shown here is one-way, from EMQX to MongoDB.
Use EMQX SQL rules to prepare fields, then map the results with the sink’s payload template. Binary or custom payloads require a suitable decoder first. In the template, quote strings and leave numbers unquoted to preserve their types. Test with representative device messages.
Yes, with a deployment sized for your workload. Capacity depends on message size and rate, document structure, indexes, and database resources. MongoDB replica sets provide redundancy and failover; sharding distributes data across shards. Benchmark the complete pipeline with representative traffic and queries.
EMQX can buffer outgoing requests and retry recoverable errors. Buffer capacity and request expiry limit how long delivery can be deferred. Monitor failed and dropped requests, test recovery after interruptions and restarts, and configure MongoDB write acknowledgments for your durability requirements.
You need EMQX with MongoDB integration, network access to the database, and write credentials. Configure the connector for your MongoDB deployment, then create a SQL rule and a sink with a collection and payload template. Enable TLS for an encrypted connection and verify a test document.
Plan your MQTT data flow, document structure, and MongoDB deployment with an EMQX expert.