MongoDB Overview
TheMONGODB connector inserts MQTT messages into MongoDB collections as documents and reads them back. Each event either inserts one document or runs a find, and models can store into a collection with STORE IN.
MongoDB suits IoT data whose shape changes over time. Store sensor readings, events, and logs without defining a table first.
Basic Syntax
Connection Configuration
MONGODB_CONFIG Parameters
MongoDB URI:
mongodb://host:port/?options or mongodb+srv://host/?options. Replica sets, TLS, timeouts, and pool size are set here as URI options. The URI is checked at deploy: one that cannot be read is refused, and the error never repeats the URI.Optional Settings
Optional Settings
Login given apart from the URI, so the password needs no percent-encoding. It takes precedence over a login in the URI. It authenticates exactly as a login in the URI would, so
authSource, authMechanism, and authMechanismProperties from the URI still apply.Credentials in the URI
A user name or password inside the URI must be percent-encoded:@ : / ? # [ ] % become %40 %3A %2F %3F %23 %5B %5D %25. A URI with an unencoded @ in the password is refused at deploy. To avoid encoding, leave the login out of the URI:
URI options and defaults
The connector applies these defaults only when the URI does not set the option itself:
Every other option, such as
retryWrites, replicaSet, or tls, is used as written in the URI.
TLS
Set TLS in the URI withtls=true. Add tlsCAFile=/path/ca.pem for a private certificate authority. tlsInsecure=true skips certificate checks; use it only in a test setup with a self-signed certificate.
Event Configuration
EVENT Parameters
An insert or a find, as a CLEAN or JSON object. See Query format.
Query format
QUERY is a JSON object, or the CLEAN form (CLEAN:{key: value} with unquoted keys and values). CLEAN is the practical form inside a LoT string. Extended JSON such as {"$oid": "…"} and {"$date": "…"} works in filters and documents.
A query with a document key inserts. Any other query is a find.
Update, delete, and aggregation are not supported.
Find options
Placeholders
Each placeholder goes in as one JSON value, so payload text is stored as sent:
- A JSON number,
true,false, ornullkeeps its type. Text that reads as a number or astrue/falseis stored as one. - Any other text is stored as a string, with its quotes, apostrophes, commas, semicolons, and braces. Dates keep their offset.
{value.json}, or a{payload.json.key}that holds an object or an array, goes in as that JSON.- Inside a quoted string (
"note: {payload}"), the value is part of that string.
Writing Data
- Basic Document Storage
- Structured Documents
- Multiple Collections
- Replica Set
Store each JSON payload with its topic:Each insert publishes a result to
DESTINATION_TOPIC:Alternative: STORE IN with Models. Instead of writing an insert query, bind a model to this connector. Each See Data Storage Overview for the full STORE IN workflow.
PUBLISH MODEL inserts one document with the model’s fields and their JSON types, plus a timestamp date unless the model has a timestamp field. MongoDB creates the collection on first use:Reading Data
A find event reads documents on demand. Publish to itsSOURCE_TOPIC, and the matching documents are published to DESTINATION_TOPIC as one JSON array:
_id as {"$oid": "…"}, dates as {"$date": "…"}, and decimals as {"$numberDecimal": "…"}:
Timed Polling
AnEVERY event runs the same find on a schedule:
When an event fails
A failed insert or find publishes nothing. The error is logged, and the event’sON ERROR block runs. A query the server refuses leaves the connector connected. Only a connection failure marks it disconnected.
While MongoDB is unreachable
After a connection failure, the next event orSTORE IN checks MongoDB at once. If MongoDB answers, the work runs. If not, the work is skipped and later checks run at most every 5 seconds. Work that arrives between checks is skipped instead of waiting out the server-selection timeout.
Each check logs how many events and STORE IN documents were skipped: a warning while MongoDB is still down, and an information line with the total when the connector reconnects.
A removed or redeployed connector closes its connections. Another connector with the same URI keeps working.
Checking the connection
-checkConnectorConnection <Name> pings the database. The reply names the database and the hosts and ports it tried, never the login or the password. The check waits at most 10 seconds.
Connection String Examples
Troubleshooting
Deploy refused: CONNECTION_STRING is not a valid MongoDB URI
Deploy refused: CONNECTION_STRING is not a valid MongoDB URI
- Start the URI with
mongodb://ormongodb+srv:// - Percent-encode
@ : / ? # [ ] %in the user name and password, or move the login toUSERNAMEandPASSWORD
Connection refused or no answer
Connection refused or no answer
- Check that MongoDB is running and listening on that host and port
- Check that a firewall allows the connection (port 27017 by default)
- For Atlas, add the broker’s address to the IP access list
Authentication failed
Authentication failed
- Check the user name and password
- Check that
authSourcenames the authentication database - Check that the user has rights on the target database
Event fails or a find returns nothing
Event fails or a find returns nothing
- Name the
collectionin every query - Use only
collection,filter,projection,sort,skip, andlimitin a find - Write
filter, and the object forms ofprojectionandsort, as JSON objects - Add a
DESTINATION_TOPICto see the result
Next Steps
Data Storage Connectors Overview
Compare all storage options.
OpenSearch Connector
Configure OpenSearch for search and analytics.

