This is the ThingsDB documentation for version v0, click here for the latest version!
Adds a new node to ThingsDB. Nodes are used for scaling and high availability.
Before using this command, make sure another node is started and waiting for a join. This can be done by starting thingsdb with the
--secret argument, for example:
thingsdb --secret "my-one-time-secret"
Next, you will see something like this:
Waiting for an invite from a node to join ThingsDB... You can use the following query to add this node: new_node('my-one-time-secret', 'node.local', 9220);
Now you can use the new_node(..) function to add the node to ThingsDB.
This function generates an event.
new_node(secret, name [, port])
||str (required)||Secret used to initially connect to the new node.|
||str (required)||Node name (host-name or IP address) of the new node.|
||int (optional)||Node port (
Best practice is to set the argument “name” to the same name as specified by the environment variable THINGSDB_NODE_NAME or the node_name found in the configuration file (view the chapter on configuration).
Returns the new node
id if successful.
Add a new node to ThingsDB:
// ThingsDB must be started on node2 using the `--secret ...` argument new_node('my-one-time-secret', 'node2.local');
Example return value in JSON format (the new node id)