Skip to content
hobbyquaker edited this page Mar 15, 2018 · 15 revisions

Topics on which mqttDB publishes

All these topics are published with retain flag set to true by mqttDB.

$db/connected

Publishes 1 when mqttDB is started and connected to the broker, publishes 2 when all documents and views are initially published, publishes 0 by last will testament when mqttDB is disconnected from the broker. Clients that modify documents or views should subscribe to this topic and be aware that no changes can be carried out when the payload is 0.

$db/rev

Publishes the database revision. This is just a number that gets incremented every time a document was created, modified or deleted.

$db/doc/<document-id>

All documents are published retained on these topics. Payload is usually a JSON object, in case of a deleted document it's an empty string.

$db/view/<view-id>

All views are published retained on these topics. Payload is usually a JSON object, in case of a deleted view it's an empty string.

Topics subscribed by mqttDB

On the following topics clients must not publish with the retain flag set to true. Clients should check the $db/connected topic before publishing on these topics (see above).

$db/get/doc/<document-id>

Trigger a publication of a document. Payload is irrelevant.

$db/get/view/<view-id>

Trigger a publication of a view. Payload is irrelevant.

$db/set/<document-id>

Create, overwrite or delete a document. Payload has to be a JSON object or - for deletion - an empty string.

$db/extend/<document-id>

Extend a document (overwrite only given properties of the document). Payload has to be a JSON object.

$db/prop/<document-id>

Set/overwrite, create or delete document properties. Examples Payloads:

  • {"method":"set", "prop": "name", "val": "new name!"}
  • {"method":"create", "prop": "name", "val": "new name!"}
  • {"method":"del", "prop": "name"}

You can use dot-Notation for prop to access nested properties.

In contrast to the set method create won't overwrite existing properties.

$db/query/<view-id>

Create, overwrite or delete a view.

Payload has to be a JSON object with a mandatory map attribute and the optional attributes reduce and filter. Use an empty string payload to delete a view.

See Views for an in-depth description on how to work with views.