Overwrite Current Value¶
Description¶
This operation overwrites the value of a key.
It is almost identical to Set Value By Key Name operation, but provides an additional parameter to control the overwrite process more flexibly.
Method¶
Backendless.Hive(hiveName).MapStore(keyName).set(objKey, value, overwrite);
where:
Argument | Description |
---|---|
hiveName |
Name of a hive where the operation is performed. String value. |
keyName |
Key name identifying a map. String value. |
objKey |
Name of the key whose value is replaced. String value. |
value |
New value for the key. Can be of any data type. |
overwrite |
When set to true , forces the rename operation and name overwrite. Boolean value. |
Return Value¶
The return value depends on the operation behavior:
When the overwrite
parameter is set to true
:
Scenario 1: If the specified key is found, the operation overwrites the value and returns false
. The false
is returned to indicate that the new key-value pair was not created, but only the existing key-value pair was updated.
Scenario 2: If the specified key is not found, then the operation creates a new value pair and returns true
.
When the overwrite
parameter is set to false
:
Scenario 1: If the specified key is found, the operation does not overwrite the value, but only returns false
indicating that the value was not overwritten and the new-key value pair was not created.
Scenario 2: If the specified key is not found, then the operation creates a new value pair and returns true
.
Example¶
The example below overwrites the current value of the "Oranges"
key with a new value 1.29
. The invocation returns false
indicating that this value is updated. As you can see, the overwrite
parameter is set to true
, hence the operation overwrites the value.
Backendless.Hive("groceryStore").MapStore("fruits").set("Oranges", 1.29, true);
where:
Argument | Description |
---|---|
"groceryStore" |
Name of a hive where the operation is performed. |
"fruits" |
Key name identifying a map. |
Codeless Reference¶
where:
Argument | Description |
---|---|
hive name |
Name of a hive where the operation is performed. |
key name |
Key name identifying a map. |
object key name |
Key name identifying a key-value pair. |
value |
A value for a key. |
overwrite |
When set to true , forces the rename operation and name overwrite. |
The return value depends on the operation behavior:
When the overwrite
parameter is set to true
:
Scenario 1: If the specified key is found, the operation overwrites the value and returns false
. The false
is returned to indicate that the new key-value pair was not created, but only the existing key-value pair was updated.
Scenario 2: If the specified key is not found, then the operation creates a new value pair and returns true
.
When the overwrite
parameter is set to false
:
Scenario 1: If the specified key is found, the operation does not overwrite the value, but only returns false
indicating that the value was not overwritten and the new-key value pair was not created.
Scenario 2: If the specified key is not found, then the operation creates a new value pair and returns true
.
Consider the following Map storage:
The example below overwrites the current value of the "Oranges"
key with a new value 1.29
.
The map will look as shown below after the Codeless logic runs: