Collections

Each collection can be thought of as an object to which properties can be assigned. We call such an object a Thing. To access something in the collection, all you need to do, is to start with a . (dot), followed by a function or property name. Another way to access the collection is to use the collection’s Id. All things which are stored in ThingsDB get an unique Id. Since the collection root is also a Thing, it has its own id.

For example, to read the collection’s ID:

.id();  // This will return the collection ID

To store something inside the collection you only need to make sure the data is attached to the collection.

For example:

// Saves a number `42`
.number = 42;

// Saves some text to property `txt`
.txt = 'Hello ThingsDB!';

// Saves a new `thing` to property `card`
.card = {
    suit: 'Spades',
    value: 1,
};

// The last value will be the return value. It may be just `nil`
nil;

Reading data from a collection works similar. Just ask for the property.

For example:

.txt;  // Returns the value of property `txt`

Result in JSON format:

"Hello ThingsDB!"

To return multiple properties at once, it is often useful to put them in an array:

[.txt, .number];  // Returns both property `txt` and `number`

And the result in JSON format:

[
    "Hello ThingsDB!",
    42
]

Stored things will get an Id (#) from ThingsDB.

For example look at our card example:

.card;  // Returns the value of property `card`

Result in JSON format (The Id (#) might differ since it is auto-generated by ThingsDB)

{
    "#": 17,
    "suit": "Spades",
    "value": 1
}

See the Collection API documentation for functions which can be used to manipulate ThingsDB data.