Difference

Difference( source, diff, ... )
Difference( source, diff, ... )
Difference( source, diff, ... )
Difference( source, diff, ... )
difference( source, diff, ... )
difference( source, diff, ... )
Difference( source, diff, ... )
Difference( source, diff, ... )

Description

The Difference function returns a SetRef object that represents all elements in the source SetRef which are not in the difference SetRef(s).

Parameters

Argument Type Definition and Requirements

source

SetRef

The source SetRef object to be compared.

diff

SetRef

One or more difference SetRef objects.

Returns

A SetRef object for the difference operation.

Examples

The query below takes the source SetRef (i.e. set reference) which is created by locating the search term "fire" in the index named "spells_by_element" and removing all difference SetRef 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 Collection of type Page.

curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "paginate": {
            "difference": [
              {
                "match": { "index": "spells_by_element" },
                "terms": "fire"
              },
              {
                "match": { "index": "spells_by_element" },
                "terms": "water"
              }
            ]
          }
        }'
client.Query(
  Paginate(
    Difference(
      Match(Index("spells_by_element"), "fire"),
      Match(Index("spells_by_element"), "water"))));
System.out.println(
    client.query(
      Paginate(
        Difference(
          Match(Index(Value("spells_by_element")), Value("fire")),
          Match(Index(Value("spells_by_element")), Value("water"))))
    ).get());
result, _ := client.Query(
    f.Paginate(
        f.Difference(
            f.MatchTerm(f.Index("spells_by_element"), "fire"),
            f.MatchTerm(f.Index("spells_by_element"), "water"),
        ),
    ),
)

fmt.Println(result)
client.query(
  Paginate(
    Difference(
      Match(Index("spells_by_element"), "fire"),
      Match(Index("spells_by_element"), "water"))))
client.query(
  q.paginate(
    q.difference(
      q.match(q.index("spells_by_element"), "fire"),
      q.match(q.index("spells_by_element"), "water")
    )
  ))
$client.query do
  paginate difference(match(index('spells_by_element'), 'fire'),
                      match(index('spells_by_element'), 'water'))
end
client.query(
    Paginate(
        Difference(
            Match(
                index: Index("spells_by_element"),
                terms: "fire"
            ),
            Match(
                index: Index("spells_by_element"),
                terms: "water"
            )
        )
    )
)
client.query(
  q.Paginate(
    q.Difference(
      q.Match(q.Index("spells_by_element"), "fire"),
      q.Match(q.Index("spells_by_element"), "water"))))
.then((ret) => console.log(ret))
HTTP/1.1 200 OK
{
  "resource": {
    "data": [ { "@ref": "classes/spells/181388642046968320" } ]
  }
}
{ "data": [ { "@ref": "classes/spells/181388642046968320" } ] }
{
  data: [
    ref(id = "181388642046968320", class = ref(id = "spells", class = ref(id = "classes")))
  ]
}
map[data:[{181388642046968320 0xc420239980 <nil>}]]
{ "data": [ { "@ref": "classes/spells/181388642046968320" } ] }
{ "data": [ { "@ref": "classes/spells/181388642046968320" } ] }
{ "data": [ { "@ref": "classes/spells/181388642046968320" } ] }
{ "data": [ { "@ref": "classes/spells/181388642046968320" } ] }
{ data:
   [ Ref(id=181388642046968320, class=Ref(id=spells, class=Ref(id=classes))) ] }

The query below is similar to the example above, but it returns instance events instead of the index tuples.

curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "paginate": {
            "difference": [
              {
                "match": { "index": "spells_by_element" },
                "terms": "fire"
              },
              {
                "match": { "index": "spells_by_element" },
                "terms": "water"
              }
            ]
          },
          "events": true
        }'
client.Query(
  Paginate(
    Difference(
      Match(Index("spells_by_element"), "fire"),
      Match(Index("spells_by_element"), "water")),
    events: true));
System.out.println(
        client.query(
           Paginate(
             Events(
               Difference(
                 Match(Index(Value("spells_by_element")), Value("fire")),
                 Match(Index(Value("spells_by_element")), Value("water"))
               )
             )
           )
        ).get());
result, _ := client.Query(
    f.Paginate(
        f.Events(
            f.Difference(
                f.MatchTerm(f.Index("spells_by_element"), "fire"),
                f.MatchTerm(f.Index("spells_by_element"), "water"),
            ),
        ),
    ),
)

fmt.Println(result)
client.query(
  Paginate(
    Difference(
      Match(Index("spells_by_element"), "fire"),
      Match(Index("spells_by_element"), "water")),
    events = true))
client.query(
  q.paginate(
    q.difference(
      q.match(q.index("spells_by_element"), "fire"),
      q.match(q.index("spells_by_element"), "water")
    ),
    events=True
  ))
$client.query do
  paginate difference(match(index('spells_by_element'), 'fire'),
                      match(index('spells_by_element'), 'water')),
           events: true
end
client.query(
    Paginate(
        Difference(
            Match(
                index: Index("spells_by_element"),
                terms: "fire"
            ),
            Match(
                index: Index("spells_by_element"),
                terms: "water"
            )
        ),
        events: true
    )
)
client.query(
  q.Paginate(
    q.Events(q.Difference(
      q.Match(q.Index("spells_by_element"), "fire"),
      q.Match(q.Index("spells_by_element"), "water")))))
.then((ret) => console.log(ret))
HTTP/1.1 200 OK
{
  "resource": {
    "data": [
      {
        "ts": 1509244539203043,
        "action": "create",
        "resource": { "@ref": "classes/spells/181388642046968320" }
      },
      {
        "ts": 1509244539223511,
        "action": "create",
        "resource": { "@ref": "classes/spells/181388642071085568" }
      }
    ]
  }
}
{
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    }
  ]
}
{
  data: [
    {
      ts: 1527002946726063,
      action: "add",
      instance: ref(id = "181388642071085568", class = ref(id = "spells", class = ref(id = "classes")))
    },
    {
      ts: 1527002946795516,
      action: "add",
      instance: ref(id = "181388642046968320", class = ref(id = "spells", class = ref(id = "classes")))
    }
  ]
}
map[data:[
  map[ts:1509244539203043 action:add instance:{181388642046968320 0xc420261160 <nil>}]
  map[ts:1509244539223511 action:add instance:{181388642071085568 0xc420261420 <nil>}]
]]
{
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    }
  ]
}
{
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    }
  ]
}
{
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    }
  ]
}
{
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    }
  ]
}
{ data:
   [ { ts: 1526677776479051,
       action: 'add',
       instance:
        Ref(id=181388642046968320, class=Ref(id=spells, class=Ref(id=classes))) },
     { ts: 1526677776479051,
       action: 'add',
       instance:
        Ref(id=181388642071085568, class=Ref(id=spells, class=Ref(id=classes))) } ] }

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve! documentation@fauna.com

Thank you for your feedback!