Skip to content

Check If Keys Exist

Description

This operation checks if specific keys exist in the specified store.

Method

Backendless.Hive(hiveName).StoreType().exists(keys);

where:

Argument                Description
hiveName Name of a hive where the operation is performed. String value.
StoreType This placeholder must be substituted with one of the following stores types: KeyValueStore, ListStore, MapStore, SetStore, SortedSetStore.
keys Represents an array of keys to check if they exist in a store. Array of string values.

Return Value

Number of found keys. Otherwise, 0 is returned if the specified keys do not exist.

Example

Check Multiple Keys

The example below checks if the "fruits" and "vegetables" keys exist in the list store.

List<String> keys = new ArrayList<>();
keys.add("fruits");
keys.add("vegetables");

Backendless.Hive("groceryStore").ListStore().exists(keys);

where:

Argument                Description
"groceryStore" Name of the hive where the operation is performed.
["fruits","vegetables"] An array of key names to check for existence.

Codeless Reference

general_api_check_if_keys_exist

where:

Argument                Description
hive name Name of a hive where the operation is performed.
type Storage type, can be one of the following: Key / Value, Sorted Set, Set, Map, List.
keys An array of keys to check for existence.

Returns the number of found keys. Otherwise, 0 is returned if the specified keys do not exist.

Consider the following Key Value storage:

sample-key-value

The example below checks if the "Japan" and "USA" keys exist in the the Key Value storage of the countries hive. The block returns a number of keys found in the store.

general_api_example_check_if_keys_exist

The output will look as shown below after the Codeless logic runs.
general_api_example_check_if_keys_exist_2


To check for a single key, use the following block. The blocks returns a boolean true or false value indicating whether the specific key exists in the store.
general_api_check_if_key_exists

where:

Argument                Description
hive name Name of a hive where the operation is performed.
type Type of the storage used for this operation.
key name Key name to check for existence.

The example below checks if the "Japan" key exists in the Key / Value store of the countries hive:

general_api_example_check_if_key_exists
The output will look as shown below after the Codeless logic runs.
general_api_example_check_if_key_exists_2