Channel Metadata

With metadata and metacounter, you can store additional information within a channel. The metadata allows you to store a Dictionary of String key-value pairs in a channel instance. If you want to store an integer with atomic increasing and decreasing operations, use the metacounter instead.

Use cases for metadata/metacounters could include tracking the number of likes, the background color, or a long description of the channel, which can each be fetched and rendered into the UI.


Create, update, retrieve, and delete a metadata

Metadata is a Dictionary that is stored within a channel. Its uses are very flexible, allowing you to customize a channel to fit you and your users' needs.

Create

To store metadata into a channel, create a Dictionary, and then pass it as an argument when calling createMetaData(). You can store multiple key-value pairs in the map.

var data = {
    'key1': 'value1',
    'key2': 'value2'
};

channel.createMetaData(data, function(response, error){
    if (error) {
        return;
    }
});

Update

The process for updating metadata is identical to creation. Values are updated for existing keys, while new key-value pairs added.

var data = {
    'key1': 'valueToUpdate1',
    'key2': 'valueToUpdate2',
    'key3': 'valueToUpdate3'
};

channel.updateMetaData(data, function(response, error){
    if (error) {
        return;
    }
});

Retrieve

To get stored metadata, create a Collection of keys, and then pass it as an argument to getMetaData(). The callback returns a Dictionary containing the corresponding key-value pairs.

var keys = [ 
    'key1',
    'key2'
];

channel.getMetaData(keys, function(response, error){
    if (error) {
        return;
    }
});

Delete

The process for deleting a metadata is as simple as creating one.

channel.deleteMetaData("key1", function(response, error){
    if (error) {
        return;
    }
});

Create, increase, decrease, retrieve, and delete a metacounter

A metacounter is a Map that is stored within a channel instance. Its primary uses are to track and update discrete indicators within a channel.

Create

To store a metacounter into a channel, create a Map, and then pass it as an argument when calling createMetaCounters(). You can store multiple key-value pairs in the map.

var counters = {
    'key1': 1,
    'key2': 2'
};

channel.createMetaCounters(counters, function(response, error){
    if (error) {
        return;
    }
});

Increase

The increase and decrease operations work similarly to getting metacounters, as described above. Create a Dictionary of keys to pass to increaseMetaCounters(), which increments the corresponding metacounters by the number you've specified.

var counters = {
    'key1': 2,    // Increases by 2.
    'key2': 3'    // Increases by 3.
};

channel.increaseMetaCounters(counters, function(response, error){
    if (error) {
        return;
    }
});

Decrease

Likewise, pass a Dictionary of keys to decreaseMetaCounters(), which decrements the metacounters by the number you've specified.

var counters = {
    'key1': 3,      // Decreases by 3.
    'key2': 4'      // Decreases by 4.
};

channel.decreaseMetaCounters(counters, function(response, error){
    if (error) {
        return;
    }
});

Retrieve

To get stored metacounters, create a Collection of keys and pass it as an argument to getMetaCounters(). The callback returns a Dictionary containing the corresponding key-value pairs.

var keys = [ 
    'key1',
    'key2'
];

channel.getMetaCounters(keys, function(response, error){
    if (error) {
        return;
    }
});

Delete

The process for deleting a metacounter is as simple as creating one.

channel.deleteMetaCounter("key1", function(response, error){
    if (error) {
        return;
    }
});