Skip to content

Rename Key

Description

This operation renames a key. The corresponding value is not impacted. After the operation is complete, the value is available with the new key name.

Method

Backendless.Hive(hiveName).[bucketType](keyName).rename(newKeyName, overwrite): Promise<void>;

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.
keyName Key name to rename. String value.
newKeyName New name for the key. String value.
overwrite When set to true, forces the rename operation and name overwrite if newKeyNamealready exists in the store.Defaults to true. Boolean value.

Return Value

true if the specified key is renamed. Otherwise returns false.

If the specified key does not exist, then the following Backendless error is returned:

{  
    "code": 27003,  
    "message": "no such key",  
    "errorData": {}  
}

Example

The example below renames the 'fruits' key to 'fruitsAndBerries'.

await Backendless.Hive('groceryStore').ListStore('fruits').rename('fruitsAndBerries')

where:

Argument                Description
'groceryStore' Name of a hive where the operation is performed.
'fruits' Key name to rename
'fruitsAndBerries' New key name in the store.

Codeless Reference
general_api_rename_key

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.
key name Key name to rename.
new name New name to assign to a key.
overwrite When set to true, forces the rename operation and name overwrite if [new-name] already exists in the store. Defaults to true.

Returns true if the specified key is renamed. Otherwise, returns false.

Consider the following Key Value storage:

sample-key-value

The following example renames the "Japan" key in the storage:

general_api_example_rename_key

Once the operation is performed, the storage will have the data as shown below:

rename-key-result