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

PUT

Endpoint URL

Important

Make sure to replace xxxx in the domain name in the request specification below to the one assigned to your application.

https://xxxx.backendless.app/api/hive/[hive-name]/set/[key]/random?count=[n-values-to-get]

where:

Argument                Description
[hive-name] Name of a hive where the operation is performed.
[key] Key name identifying a set.
[n-values-to-get] The number of elements that must be retrieved and deleted from the set. Defaults to 1.

Request Headers

None.

Request Body

None.

Response Body

A JSON array containing deleted values. Each individual value is of a JSON 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.

curl --location --request PUT "https://xxxx.backendless.app/api/hive/transport/set/cars/random?count=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