Difference
Difference( source, diff, ... )
Difference( source, diff, ... )
Difference( source, diff, ... )
Difference( source, diff, ... )
difference( source, diff, ... )
Difference( source, diff, ... )
Description
The Difference
function compares the source
, which can be an
Array or Set, with the item(s) provided by diff
, and
returns all of the items that exist in source
that do not exist in
diff
.
The run time of For query timeout errors, you may specify a larger query timeout via the driver that you are using. |
Examples
The following query takes the source Set Reference which is
created by locating the search term "fire" in the index named
"spells_by_element" and removing all difference Set Reference
which was created by locating the search term "water" in the index named
"spells_by_element". The Paginate
function materialized the
results of the Difference
operation in a Page.
ObjectV(data: Arr(RefV(id = "181388642046968320", collection = RefV(id = "spells", collection = RefV(id = "collections")))))
map[data:[{181388642046968320 0xc000142270 0xc000142270 <nil>}]]
{data: [ref(id = "181388642046968320", collection = ref(id = "spells", collection = ref(id = "collections")))]}
{ data: [ Ref(Collection("spells"), "181388642046968320") ] }
{'data': [Ref(id=181388642046968320, collection=Ref(id=spells, collection=Ref(id=collections)))]}
{ data: [ Ref(Collection("spells"), "181388642046968320") ] }
The following query is similar to the example above, but it returns document events instead of the index tuples:
ObjectV(data: Arr(ObjectV(ts: LongV(1603756252570000),action: StringV(add),document: RefV(id = "181388642046968320", collection = RefV(id = "spells", collection = RefV(id = "collections")))), ObjectV(ts: LongV(1603756252570000),action: StringV(add),document: RefV(id = "181388642071085568", collection = RefV(id = "spells", collection = RefV(id = "collections")))), ObjectV(ts: LongV(1603756252570000),action: StringV(remove),document: RefV(id = "181388642071085568", collection = RefV(id = "spells", collection = RefV(id = "collections"))))))
map[data:[map[action:add document:{181388642046968320 0xc0000b1530 0xc0000b1530 <nil>} ts:1603747155400000] map[action:add document:{181388642071085568 0xc0000b1710 0xc0000b1710 <nil>} ts:1603747155400000] map[action:remove document:{181388642071085568 0xc000160090 0xc000160090 <nil>} ts:1603747155400000]]]
{data: [{ts: 1594315458560000, action: "add", document: ref(id = "181388642046968320", collection = ref(id = "spells", collection = ref(id = "collections")))}, {ts: 1594315458560000, action: "add", document: ref(id = "181388642071085568", collection = ref(id = "spells", collection = ref(id = "collections")))}, {ts: 1594315458560000, action: "remove", document: ref(id = "181388642071085568", collection = ref(id = "spells", collection = ref(id = "collections")))}]}
{
data: [
{
ts: 1592269416750000,
action: 'add',
document: Ref(Collection("spells"), "181388642046968320")
},
{
ts: 1592269416750000,
action: 'add',
document: Ref(Collection("spells"), "181388642071085568")
},
{
ts: 1592269416750000,
action: 'remove',
document: Ref(Collection("spells"), "181388642071085568")
}
]
}
{'data': [{'ts': 1592859673180000, 'action': 'add', 'document': Ref(id=181388642046968320, collection=Ref(id=spells, collection=Ref(id=collections)))}, {'ts': 1592859673180000, 'action': 'add', 'document': Ref(id=181388642071085568, collection=Ref(id=spells, collection=Ref(id=collections)))}, {'ts': 1592859673180000, 'action': 'remove', 'document': Ref(id=181388642071085568, collection=Ref(id=spells, collection=Ref(id=collections)))}]}
{
data: [
{
ts: 1624310400390000,
action: 'add',
document: Ref(Collection("spells"), "181388642046968320")
},
{
ts: 1624310400390000,
action: 'add',
document: Ref(Collection("spells"), "181388642071085568")
},
{
ts: 1624310400390000,
action: 'remove',
document: Ref(Collection("spells"), "181388642071085568")
}
]
}
The following query demonstrates how various arrays are compared:
Arr(Arr(StringV(A)), Arr(StringV(D)), Arr())
[[A] [D] []]
[["A"], ["D"], []]
[ [ 'A' ], [ 'D' ], [] ]
[['A'], ['D'], []]
[ [ 'A' ], [ 'D' ], [] ]
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!