Skip to content

Get Rank

Description

This operation returns the rank of a specific item from the sorted set. 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.

Method

POST

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]/get-rank

where:

Argument                Description
[hive-name] Name of a hive where the operation is performed.
[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

A JSON object with the structure shown below:

{  
    "value": <item>,  
    "reverse": <orderControl>  
}

where:

Argument                Description
<item> Value to get the rank of. Must be a valid JSON data type.
<orderControl> Optional parameter, defaults to false.  When set to false, items in the specified sorted set are sorted in the ascending order.  When set to true, items are sorted in descending order.

Response Body

The rank of the specified item. Otherwise, returns the null if the item does not exist.

Example

The example below returns the rank of the "Player A" item from the players sorted set. Since the reverse parameter is set to true, the items in the sorted set are arranged in the descending order.

curl --location --request GET "https://xxxx.backendless.app/api/hive/leaderboard/sorted-set/players/get-rank" \  
        --header 'Content-Type: application/json \  
        --data-raw '[  
            "value": "Player A",  
            "reverse": true  
        ]'

where:

Argument                Description
leaderboard Name of a hive in the system.
players Name of a sorted set where the operation takes place.

Codeless Reference
sorted_set_api_get_rank

where:

Argument                Description
hive name Name of a hive where the operation is performed.
key name Key name identifying a sorted set.
value Value to get the rank of. Must be the same value/object/type as stored in the sorted set.
reverse When set to true, items are sorted in ascending order. If set to false, items are ordered in descending order.

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.

Returns the rank of the specified value. Returns null if the value does not exist.

Consider the following Sorted Set storage:
sorted_set_api_example_all_blocks

The example below retrieves the rank of a value named "Julia".
sorted_set_api_example_get_rank

The output will look as shown below after the Codeless logic runs:
sorted_set_api_example_get_rank_2