Skip to content

Check If Keys Exist

Description

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

Method

// Check One Key

Backendless.Hive(hiveName).[bucketType](keyName).exist(): Promise<number>;

// Check Multiple Keys

Backendless.Hive(hiveName).[bucketType].exist(keys): Promise<number>;

where:

Argument                Description
hiveName Name of a hive where the operation is performed. String value.
[bucketType] 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.
keyName Identifies a single key to check if it exists in a store. String value.

Return Value

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

Example

Check One Key

This example checks if the 'fruits' key exists in the key-value store.

await Backendless.Hive('groceryStore').KeyValueStore('fruits').exist();

where:

Argument                Description
'groceryStore' Name of the hive where the operation is performed.
'fruits' Key name to check for existence.

Check Multiple Keys

The example below checks if the 'fruits' and 'vegetables' keys exist in the key-value store.

await Backendless.Hive('groceryStore').KeyValueStore.exist(['fruits', 'vegetables'])

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