Custom Queries

One of the tools that the AnythingDB module makes available to users is called Custom Queries. T​his function offers the ability to perform queries directly on the AnythingDB database where the information of the different data models (Things and Categories) defined by the users is stored.

In this way, you will be able to perform complex queries on the data stored in the platform and similarly develop and test complex queries that can later be incorporated into the business logic implemented in the Workers of the Function module.

To access this section, in the AnythingDB section, click Custom Queries.

Figure 1.

Thing Diagram

To perform queries correctly, you need to know how the data is stored within the AnythingDB database in order to exploit its different possibilities. To help you understand this structure, a diagram is shown below, corresponding to the right half of the screen, where the data structure followed by the different elements stored on the platform is defined.

Figure 2.

Running AnythingDB Queries

To run queries, enter the code with the appropriate format in the text box located below the Run button.

Figure 3.
By default, the code corresponding to one of the examples offered by the platform is included. You can see the different fields that can be included when making queries. Following is an explanation for each of them.
The Anything DB query itself with the data to be collected from the database.
True/False, define a count of items matching the query that should be returned in the result or not.
Defines the number of elements to display in the response
Variables referenced in the query
The response returned by the platform will content the following parameters:
Response status code
Number of elements that matched the query
True / false, depending on existing errors
(stats): Stats about the execution of the query
See the pagination section below for more information
True / false depending on if all elements were returned in result
Elements returned by the query.

Figure 4.

Example Queries

To help you understand this tool, three query examples are included that can be chosen from the drop down menu located at the top of the page.

Figure 5.

To use these examples, replace the values in the bindVars parameter of the body.

Using AnythingDB Queries from a Worker

A powerful way to explore the use of AnythingDB from within the SmartWorks platform is by automating these queries through the use of functions. To be able to incorporate calls in the functions, use the https protocol using a POST call.

You must have the necessary credentials to make the call following the basic operation of our API.

The body of the POST call must include in JSON format the fields defined above, where the query to be made will be included.


Occasionally, the result returned after a query will not show all the results. This will be indicated in the response field with the title hasMore. To access the rest of the results, use the field "id" that is returned in the query result.

Make a call with the URL indicated in the previous section, but incorporate the ID that was returned in the response.

You can make calls to this URL sequentially until you get the rest of the values. The hasMore field will return false when the last data has been displayed.


To learn more about AnythingDB Beta, you can access its documentation by clicking .