setEqualsTo - Check equality of two sets
setEqualsTo
returns true if array1
has the same elements as array2
.
Note
When comparing array1
and array2
, duplicates will be discarded. This means two arrays of differing lengths but the same unique elements will be considered equal.
Syntax
Like many functions in DataPrime, setEqualsTo
supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.
Arguments
Name | Type | Required | Description |
---|---|---|---|
array1 | array of type T | true | T must be either string , bool , number , interval , timestamp , regexp or enum |
array2 | array of type T | true | T must be either string , bool , number , interval , timestamp , regexp or enum |
Example - Basic usage
Consider the following document:
{
"array_1": ["val1", "val1", "val2", "val2", "val3"],
"array_2": ["val1", "val2", "val3", "val3", "val3"]
}
We can see that while these two arrays have different counts of the values, they both possess the same unique values. We can check this, using setEqualsTo
:
This results in the following document:
{
"array_1": ["val1", "val1", "val2", "val2", "val3"],
"array_2": ["val1", "val2", "val3", "val3", "val3"],
"arrays_equal": true
}
Theme
Light