MongoDB Data Source
MongoDB data source is for environments where user/ACL/blacklist data is already managed in MongoDB.
Suitable Scenarios
- Existing identity/policy services already store data in MongoDB.
- You want collection + filter based integration without schema migration.
- You need broker cache-first auth behavior.
Core Capabilities
- Sync user/ACL/blacklist data from MongoDB.
- Configure dedicated collections via
collection_user/collection_acl/collection_blacklist. - Configure dedicated JSON filters via
query_user/query_acl/query_blacklist.
Runtime Model (Brief)
- Broker periodically reads MongoDB data.
- Parsed data is written into local cache.
- CONNECT and access checks use cache first (no per-request MongoDB query).
Configuration
Key fields in mongodb_config:
mongodb_uri: MongoDB connection URIdatabase: database nameusername/password: credentials (optional, can be embedded in URI)collection_user: user collectioncollection_acl: ACL collectioncollection_blacklist: blacklist collectionquery_user: JSON filter string for usersquery_acl: JSON filter string for ACLsquery_blacklist: JSON filter string for blacklist
Field Contract
User document
Required:
usernamepassword
Optional:
saltis_superuser(bool,0|1, or"true"|"false")created(DateTime, unix timestamp, or parseable datetime string)
ACL document
Required:
permission(1|0orAllow|Deny)actionoraccess(0..5orAll|Subscribe|Publish|PubSub|Retain|Qos)topicortopics(array)
Optional:
usernameclientidipaddr(oripaddress)
Blacklist document
Required:
blacklist_type(ClientId/User/Ip/ClientIdMatch/UserMatch/IPCIDR)resource_nameend_time
Optional:
desc
Example
toml
[[mqtt.auth]]
authn_type = "password_based"
[mqtt.auth.config.storage_config]
storage_type = "mongodb"
[mqtt.auth.config.storage_config.mongodb_config]
mongodb_uri = "mongodb://127.0.0.1:27017"
database = "mqtt"
username = ""
password = ""
collection_user = "mqtt_user"
collection_acl = "mqtt_acl"
collection_blacklist = "mqtt_blacklist"
query_user = "{}"
query_acl = "{}"
query_blacklist = "{}"Notes
query_*must be valid JSON (for example{}or{"enabled": true}).- Add indexes for fields like
username,clientid,resource_name. - Keep
blacklist_typeenum values consistent to avoid skipped records.
