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 from the set.

Examples


Delete Multiple Values

The example below returns and deletes two random values from the 'cars' set.

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.


Delete a Single Value

When this operation is used without the count parameter, then only one value is deleted from the set. The example below returns and deletes one random value from the 'cars' set.

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

where:

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


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