Skip to content

Delete Random Key Items

Description

This operation returns the specified number of random elements and deletes them afterwards from a set.

Method

Backendless.Hive(hiveName).SetStore(keyName).getRandomAndDelete(count): Promise<values[]>;

where:

Argument                Description
hiveName Name of a hive where the operation is performed. String value.
keyName Key name identifying a set. String value.
count Optional parameter. Identifies the number of values to delete and return in the response. Defaults to 1.

Return Value

An array containing deleted values. Each individual value is of any data type.

Example

The example below returns two random values and deletes them from the 'cars' set. By specifying the count parameter you can return/delete the specified number of elements.

await Backendless.Hive('transport').SetStore('cars').getRandomAndDelete(2)

where:

Argument                Description
'transport' Name of a hive where the operation is performed.
'cars' Key name identifying a set.

Response Example

[  
    "Sedan",  
    "Crossover"  
]

Codeless Reference

set_api_delete_random_key_items

where:

Argument                Description
hive name Name of a hive where the operation is performed.
key name Key name identifying a set.
count Specify the number of items to delete.

Returns a list containing deleted values.

Consider the following Set storage:
set_api_example_all_blocks

The example below deletes a random value from the "cars" set:

set_api_example_delete_random_key_items

The logic produces the following output:

set_api_example_delete_random_key_items_2