Skip to content

Decrement Score

Description

This operation decrements the score of an item by the specified number.

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]/sorted set/[key]/decrement

where:

Argument                Description
[hive-name] Name of a hive in the system.
[key] Key name identifying a sorted set.

Request Headers

Content-Type:application/json

where:

Argument                Description
Content-Type Must be set to application/json. This header is mandatory.

Request Body

The request body must be a JSON object with the structure shown below:

{  
  "scoreValue": [decrementValue],  
  "value": [itemValue]  
}

where:

Argument                Description
[decrementValue] A double value that the existing score will be decremented by.
[itemValue] An exact value as one already in the sorted set. The value identifies a score/value pair. The score of the corresponding value in the sorted set will be decremented by the number in the scoreValue parameter.

Response Body

The decremented score of the item.

Example

The example below decrements the score associated with the value "John" by 3.

curl --location --request PUT "https://xxxx.backendless.app/api/hive/leaderboard/sorted set/players/decrement \  
  --header 'Content-Type: application/json' \  
  --data-raw '[  
    "scoreValue": 3,  
    "value": "John"  
  ]'

where:

Argument                Description
leaderboard Name of a hive in the system.
players Name of a sorted set where to decrement the score of an item.

Codeless Reference

sorted_set_api_decrement_score

where:

Argument                Description
hive name Name of a hive where the operation is performed.
key name Key name identifying a sorted set.
value An exact value as one already in the sorted set. The value identifies a score/value pair. The score of the corresponding value in the sorted set will be decremented by the number in the decrement by parameter.
decrement by Specify the number to decrement the score of the value.

The operation returns the decremented score of the item.

Consider the following Sorted Set storage:
sorted_set_api_example_all_blocks

The example below decrements the score of a value "John" by 3:
sorted_set_api_example_decrement_score


The output will look as shown below after the Codeless logic runs.
sorted_set_api_example_decrement_score_2
Note how the decremented score forced the score/value pair to change its current position(rank). Before the operation the rank of the "John" value was 1, and after the operation the rank became 0.

Rank in a sorted set determines the position of an element. For more information about the rank, refer to the Hive Overview section of this guide.