Skip to content

Difference

Description

This operation finds the difference between the primary (first) set and all other specified sets. To find the difference, the operation subtracts identical values across multiple sorted sets and returning the remainder (i.e. the difference) in a new sorted set. The first sorted set in the request is considered the main sorted set whose remainder is left after the subtraction operation.

Important

The subtraction is performed only on values - scores are not checked for equality.

Method

Backendless.Hive( hiveName ).SortedSetStore.difference( keyNames ): Promise<items>;

where:

Argument                Description
hiveName Name of a hive where the operation is performed. String value.
keyNames An array containing key names each identifying a sorted-set. Must be an array of string values.

Return Value

An array of arrays. Each element of the response array is another array containing a score/value pair.

Example

Consider the following sorted sets:

sorted-set-difference

The example below finds the difference between the 'League1Players' and the 'League2Players' sorted sets:

await Backendless.Hive( 'leaderboard' ).SortedSetStore.difference( ['League1Players', 'League2Players'] )

where:

Argument                Description
'leaderboard' Name of the hive in the system.

Response

[  
  [  
    11,  
    "Charlie"  
  ],  
  [  
    13,  
    "Adam"  
  ]  
]

Codeless Reference

sorted_set_api_difference

where:

Argument                Description
hive name Name of a hive where the operation is performed.
key name A list containing key names identifying unique sorted sets.

Returns a list of lists. Each element of the response list is another list containing a score/value pair.

Consider the following Sorted Set storage:
sorted_set_api_example_union_difference_intersection

The example below subtracts identical values across the specified sorted sets (i.e. "players", "players_2") and returns the remainder (i.e. the difference) in a new sorted set. The first sorted set in the request is considered the main sorted set whose remainder is left after the subtraction operation.
sorted_set_api_example_difference

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