Paginate

Paginate( input, [ts], [after], [before], [size], [events], [sources] )
Paginate( input )
Paginate( input, [ts], [after], [before], [size], [events], [sources] )
Paginate( input, [cursor], [ts], [size], [sources], [events] )
paginate( input, [ts], [after], [before], [size], [events], [sources] )
paginate  input, [ts], [after], [before], [size], [events], [sources]
Paginate( input, [ts], [after], [before], [size], [events], [sources] )
Paginate( input, param_object )

Description

The Paginate function simplifies the traversal of a query’s results. It is best utilized when the result of a query returns more than one object or an unknown number of objects. It provides cursor-like semantics allowing the caller to walk both forward and backward in configurable-sized pages through the results.

Parameters

Field name Field type Definition and requirements

input

Set or Ref

A set, or ref, to paginate.

param_object

The param_object fields are described below.

param_object

Field name Field type Definition and requirements

ts

Optional, default current. Return the result set at the specified point in time (number of UNIX microseconds or a Timestamp).

after

Optional - Return the next page of results after this cursor (inclusive).

before

Optional - Return the previous page of results before this cursor (exclusive).

size

Optional - default 64. Maximum number of results to return in a single page. The maximum page size is 100,000 results.

events

Optional - default false. If true, return a page from the event history of the set.

sources

Optional - default false. If true, includes the source of truth providing why this object was included in the result set.

Field name Field type Definition and requirements

input

Set or Ref

A set, or ref, to paginate.

Field name Field type Definition and requirements

input

Set or Ref

A set, or ref, to paginate.

cursor

Optional - An object that describes the page of results to return. The object should have a single field, named before or after, and the value should point to the item representing the start of the previous or next page of results, respectively.

The cursor object by using the Before or After functions:

cursor = Before(Ref(Collection("Letters"), 104))
cursor = After(Ref(Collection("Letters"), 104))

ts

Optional - default current. Return the result set at the specified point in time (number of UNIX microseconds or a Timestamp).

size

Optional - default 64. Maximum number of results to return in a single page. The maximum page size is 100,000 results.

sources

Optional - default false. If true, includes the source of truth providing why this object was included in the result set.

events

Optional - default false. If true, return a page from the event history of the set.

Field name Field type Definition and requirements

input

Set or Ref

A set, or ref, to paginate.

ts

Optional - default current. Return the result set at the specified point in time (number of UNIX microseconds or a Timestamp).

after

Optional - Return the next page of results after this cursor (inclusive).

before

Optional - Return the previous page of results before this cursor (exclusive).

size

Optional - default 64. Maximum number of results to return in a single page. The maximum page size is 100,000 results.

events

Optional - default false. If true, return a page from the event history of the set.

sources

Optional - default false. If true, includes the source of truth providing why this object was included in the result set.

Returns

A "builder" object with methods to set additional options. Each "builder" object method accepts one parameter which sets one specific pagination option:

Method name Parameter type Definition and requirements

ts

Optional - default current. Return the result set at the specified point in time (number of UNIX microseconds or a Timestamp).

after

Optional - Return the next page of results after this cursor (inclusive).

before

Optional - Return the previous page of results before this cursor (exclusive).

cursor

Optional - An object that describes the page of results to return. The object should have a single field, named before or after, and the value should point to the item representing the start of the previous or next page of results, respectively.

size

Optional - default 64. Maximum number of results to return in a single page. The maximum page size is 100,000 results.

events

Optional - default false. If true, return a page from the event history of the set.

sources

Optional - default false. If true, includes the source of truth providing why this object was included in the result set.

Each method returns an updated "builder" object after setting its specific option.

When the "builder" object is "resolved", by the end of the query or by using it within a function that accepts a set or array, the pagination results are returned as a Page object.

A Page object.

Page object

A Page contains an array of results and other decorated elements. In some cases the entire result set may not fit into the array, so other fields (the cursor fields) allow you to walk the results set in blocks (like pages in a book). The cursor fields retrieve blocks of results before or after the current page of results. When Pages are passed to functions that accept arrays, only the array element of the Page is examined or transformed. Other elements of the Page, such as the cursor, remain unaffected and are passed directly through to the output.

Field Type Description

data

The elements in the page.

after

The cursor for the next page, inclusive. Optional.

before

The cursor for the previous page, exclusive. Optional.

Cursor

A cursor is an object used as a marker to indicate a position within a set. The cursor has a structure identical to the associated index’s values field; the same fields with the same types, in the same order.

Cursor matching is prefix-based. That means that if your index contains two or more fields, you only need to specify the first field to achieve a match. You may have to specify additional fields if there are multiple index entries that would match the first field.

A before cursor indicates the first item in a page of results. It is used to compute the page of results prior to the before cursor. The page before the current page excludes the before cursor.

An after cursor indicates the item after the last item in a page of results. It is used to compute the page of results beginning with the after cursor. The page after the current pages includes the after cursor.

The type of pagination cursor depends on whether the page is from a set, or from an events timeline. Set cursors may be a single scalar value, or an Array of values.

Events timeline cursors may be one of:

  • An Integer representing a timestamp.

  • A Timestamp.

  • A Date. Dates are interpreted as midnight on that date, in UTC.

  • An partial Event object: ts, ts and action, or all of ts, action, and resource must be specified.

It’s possible to dead-reckon through a set by specifying a synthetic cursor. For a set in descending order, { "before": null } or { "after": 0 } yields the first and last pages of the set, respectively.

Examples

The following query paginates the set of letters (established in the Index tutorials), but sets the size option to 3 to reduce the size of the result set:

Value result = await client.Query(
  Paginate(
    Match(Index("all_letters")),
    size: 3
  )
);
result, err := client.Query(
    f.Paginate(
      f.Match(f.Index("all_letters")),
      f.Size(3)))

if (err != nil) {
  fmt.Println(err)
} else {
  fmt.Println(result)
}
System.out.println(
    client.query(
        Paginate(Match(Index("all_letters")))
        .size(3)
    ).get());
client.query(
  q.Paginate(
    q.Match(q.Index("allLetters")),
    { size: 3 }
  )
)
.then((ret) => console.log(ret))
print(client.query(
  q.paginate(
    q.match(q.index("all_letters")),
    size = 3
  )
))
Not available in this language yet.
println(Await.result(
  client.query(
    Paginate(
      Match(Index("all_letters")),
      size = 3
    )
  ),
  5.seconds
))
Not available in this language yet.
FaunaDB.Types.ObjectV
{
  "object": {
    "after": [
      {
        "@ref": {
          "id": "104",
          "collection": {
            "@ref": {
              "id": "Letters",
              "collection": {
                "@ref": {
                  "id": "collections"
                }
              }
            }
          }
        }
      }
    ],
    "data": [
      {
        "@ref": {
          "id": "101",
          "collection": {
            "@ref": {
              "id": "Letters",
              "collection": {
                "@ref": {
                  "id": "collections"
                }
              }
            }
          }
        }
      },
      {
        "@ref": {
          "id": "102",
          "collection": {
            "@ref": {
              "id": "Letters",
              "collection": {
                "@ref": {
                  "id": "collections"
                }
              }
            }
          }
        }
      },
      {
        "@ref": {
          "id": "103",
          "collection": {
            "@ref": {
              "id": "Letters",
              "collection": {
                "@ref": {
                  "id": "collections"
                }
              }
            }
          }
        }
      }
    ]
  }
}
map[after:[{104 0xc0004c3500 0xc0004c3500 <nil>}] data:[{101 0xc0004c36b0 0xc0004c36b0 <nil>} {102 0xc0004c3860 0xc0004c3860 <nil>} {103 0xc0004c3a10 0xc0004c3a10 <nil>}]]
{after: [ref(id = "104", collection = ref(id = "Letters", collection = ref(id = "collections")))], data: [ref(id = "101", collection = ref(id = "Letters", collection = ref(id = "collections"))), ref(id = "102", collection = ref(id = "Letters", collection = ref(id = "collections"))), ref(id = "103", collection = ref(id = "Letters", collection = ref(id = "collections")))]}
{ after: [ Ref(Collection("Letters"), "104") ],
  data:
   [ Ref(Collection("Letters"), "101"),
     Ref(Collection("Letters"), "102"),
     Ref(Collection("Letters"), "103") ] }
{'after': [Ref(id=104, collection=Ref(id=Letters, collection=Ref(id=collections)))], 'data': [Ref(id=101, collection=Ref(id=Letters, collection=Ref(id=collections))), Ref(id=102, collection=Ref(id=Letters, collection=Ref(id=collections))), Ref(id=103, collection=Ref(id=Letters, collection=Ref(id=collections)))]}
{after: [ref(id = "104", collection = ref(id = "Letters", collection = ref(id = "collections")))], data: [ref(id = "101", collection = ref(id = "Letters", collection = ref(id = "collections"))), ref(id = "102", collection = ref(id = "Letters", collection = ref(id = "collections"))), ref(id = "103", collection = ref(id = "Letters", collection = ref(id = "collections")))]}

The following query repeats the previous query, with the addition of applying the after cursor from the previous result to return the next page of results:

Value result = await client.Query(
  Paginate(
    Match(Index("all_letters")),
    after: Ref(Collection("Letters"), 104),
    size: 3
  )
);
result, err := client.Query(
    f.Paginate(
      f.Match(f.Index("all_letters")),
      f.After(f.RefCollection(f.Collection("Letters"), 104)),
      f.Size(3)))

if (err != nil) {
  fmt.Println(err)
} else {
  fmt.Println(result)
}
System.out.println(
    client.query(
        Paginate(Match(Index("all_letters")))
        .size(3)
        .after(Ref(Collection("Letters"), "104"))
    ).get());
client.query(
  q.Paginate(
    q.Match(q.Index("all_letters")),
    {
      size: 3,
      after: [ q.Ref(q.Collection("Letters"), "104") ]
    }
  )
)
.then((ret) => console.log(ret))
print(client.query(
  q.paginate(
    q.match(q.index("all_letters")),
    after = q.ref(q.collection("Letters"), 104),
    size = 3
  )
))
Not available in this language yet.
println(Await.result(
  client.query(
    Paginate(
      Match(Index("all_letters")),
      size = 3,
      cursor = After(Ref(Collection("Letters"), "104"))
    )
  ),
  5.seconds
))
Not available in this language yet.
FaunaDB.Types.ObjectV
{
  "object": {
    "before": [
      {
        "@ref": {
          "id": "104",
          "collection": {
            "@ref": {
              "id": "Letters",
              "collection": {
                "@ref": {
                  "id": "collections"
                }
              }
            }
          }
        }
      }
    ],
    "after": [
      {
        "@ref": {
          "id": "107",
          "collection": {
            "@ref": {
              "id": "Letters",
              "collection": {
                "@ref": {
                  "id": "collections"
                }
              }
            }
          }
        }
      }
    ],
    "data": [
      {
        "@ref": {
          "id": "104",
          "collection": {
            "@ref": {
              "id": "Letters",
              "collection": {
                "@ref": {
                  "id": "collections"
                }
              }
            }
          }
        }
      },
      {
        "@ref": {
          "id": "105",
          "collection": {
            "@ref": {
              "id": "Letters",
              "collection": {
                "@ref": {
                  "id": "collections"
                }
              }
            }
          }
        }
      },
      {
        "@ref": {
          "id": "106",
          "collection": {
            "@ref": {
              "id": "Letters",
              "collection": {
                "@ref": {
                  "id": "collections"
                }
              }
            }
          }
        }
      }
    ]
  }
}
map[after:[{107 0xc000134810 0xc000134810 <nil>}] before:[{104 0xc000134660 0xc000134660 <nil>}] data:[{104 0xc0001349c0 0xc0001349c0 <nil>} {105 0xc000134b70 0xc000134b70 <nil>} {106 0xc000134d20 0xc000134d20 <nil>}]]
{before: [ref(id = "104", collection = ref(id = "Letters", collection = ref(id = "collections")))], after: [ref(id = "107", collection = ref(id = "Letters", collection = ref(id = "collections")))], data: [ref(id = "104", collection = ref(id = "Letters", collection = ref(id = "collections"))), ref(id = "105", collection = ref(id = "Letters", collection = ref(id = "collections"))), ref(id = "106", collection = ref(id = "Letters", collection = ref(id = "collections")))]}
{ before: [ Ref(Collection("Letters"), "104") ],
  after: [ Ref(Collection("Letters"), "107") ],
  data:
   [ Ref(Collection("Letters"), "104"),
     Ref(Collection("Letters"), "105"),
     Ref(Collection("Letters"), "106") ] }
{'before': [Ref(id=104, collection=Ref(id=Letters, collection=Ref(id=collections)))], 'after': [Ref(id=107, collection=Ref(id=Letters, collection=Ref(id=collections)))], 'data': [Ref(id=104, collection=Ref(id=Letters, collection=Ref(id=collections))), Ref(id=105, collection=Ref(id=Letters, collection=Ref(id=collections))), Ref(id=106, collection=Ref(id=Letters, collection=Ref(id=collections)))]}
{before: [ref(id = "104", collection = ref(id = "Letters", collection = ref(id = "collections")))], after: [ref(id = "107", collection = ref(id = "Letters", collection = ref(id = "collections")))], data: [ref(id = "104", collection = ref(id = "Letters", collection = ref(id = "collections"))), ref(id = "105", collection = ref(id = "Letters", collection = ref(id = "collections"))), ref(id = "106", collection = ref(id = "Letters", collection = ref(id = "collections")))]}

The following query paginates the set of distinct "spells" documents with a fire or water element:

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

fmt.Println(result)
client.query(
  Paginate(
    Union(
      Match(Index("spells_by_element"), "fire"),
      Match(Index("spells_by_element"), "water"))))
client.query(
  q.paginate(
    q.union(
      q.match(q.index("spells_by_element"), "fire"),
      q.match(q.index("spells_by_element"), "water")
    )
  ))
$client.query do
  paginate union(match(index('spells_by_element'), 'fire'),
                 match(index('spells_by_element'), 'water'))
end
client.query(
    Paginate(
        Union(
            Match(
                index: Index("spells_by_element"),
                terms: "fire"
            ),
            Match(
                index: Index("spells_by_element"),
                terms: "water"
            )
        )
    )
)
client.query(
  q.Paginate(
    q.Union(
      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" },
      { "@ref": "classes/spells/181388642071085568" },
      { "@ref": "classes/spells/181388642088911360" }
    ]
  }
}
{
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" },
    { "@ref": "classes/spells/181388642088911360" }
  ]
}
{
  data: [
    ref(id = "181388642046968320", collection = ref(id = "spells", collection = ref(id = "collections"))),
    ref(id = "181388642071085568", collection = ref(id = "spells", collection = ref(id = "collections"))),
    ref(id = "181388642088911360", collection = ref(id = "spells", collection = ref(id = "collections")))
  ]
}
map[data:[{181388642046968320 0xc4201c7dc0 <nil>} {181388642071085568 0xc4201c7fe0 <nil>} {181388642088911360 0xc42021c220 <nil>}]]
{
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" },
    { "@ref": "classes/spells/181388642088911360" }
  ]
}
{
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" },
    { "@ref": "classes/spells/181388642088911360" }
  ]
}
{
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" },
    { "@ref": "classes/spells/181388642088911360" }
  ]
}
{
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" },
    { "@ref": "classes/spells/181388642088911360" }
  ]
}
{ data:
  [ Ref(id=181388642046968320, collection=Ref(id=spells, collection=Ref(id=collections))),
    Ref(id=181388642071085568, collection=Ref(id=spells, collection=Ref(id=collections))),
    Ref(id=181388642088911360, collection=Ref(id=spells, collection=Ref(id=collections))) ] }

The following query returns the same set of results as the previous query, but by setting the sources option to true, the source of the match that included the entry in the set is included in the result:

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

fmt.Println(result)
client.query(
  Paginate(
    Union(
      Match(Index("spells_by_element"), "fire"),
      Match(Index("spells_by_element"), "water")),
    sources = true))
client.query(
  q.paginate(
    q.union(
      q.match(q.index("spells_by_element"), "fire"),
      q.match(q.index("spells_by_element"), "water")
    ),
    sources=True
  ))
$client.query do
  paginate union(match(index('spells_by_element'), 'fire'),
                 match(index('spells_by_element'), 'water')),
           sources: true
end
client.query(
    Paginate(
        Union(
            Match(
                index: Index("spells_by_element"),
                terms: "fire"
            ),
            Match(
                index: Index("spells_by_element"),
                terms: "water"
            )
        ),
        sources: true
    )
)
client.query(
  q.Paginate(
    q.Union(
      q.Match(q.Index('spells_by_element'), 'fire'),
      q.Match(q.Index('spells_by_element'), 'water'),
    ),
    { sources: true },
  )
)
.then((ret) => console.log(ret))
HTTP/1.1 200 OK
{
  "resource": {
    "data": [
      {
        "value": { "@ref": "classes/spells/181388642046968320" },
        "sources": [
          {
            "@set": {
              "match": { "@ref": "indexes/spells_by_element" },
              "terms": "fire"
            }
          }
        ]
      },
      {
        "value": { "@ref": "classes/spells/181388642071085568" },
        "sources": [
          {
            "@set": {
              "match": { "@ref": "indexes/spells_by_element" },
              "terms": "fire"
            }
          },
          {
            "@set": {
              "match": { "@ref": "indexes/spells_by_element" },
              "terms": "water"
            }
          }
        ]
      },
      {
        "value": { "@ref": "classes/spells/181388642088911360" },
        "sources": [
          {
            "@set": {
              "match": { "@ref": "indexes/spells_by_element" },
              "terms": "water"
            }
          }
        ]
      }
    ]
  }
}
{
  "data": [
    {
      "value": { "@ref": "classes/spells/181388642046968320" },
      "sources": [
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "fire"
          }
        }
      ]
    },
    {
      "value": { "@ref": "classes/spells/181388642071085568" },
      "sources": [
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "fire"
          }
        },
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "water"
          }
        }
      ]
    },
    {
      "value": { "@ref": "classes/spells/181388642088911360" },
      "sources": [
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "water"
          }
        }
      ]
    }
  ]
}
{
  data: [
    {
      value: ref(id = "181388642046968320", collection = ref(id = "spells", collection = ref(id = "collections"))),
      sources: [
        {
          @set = {
            match: ref(id = "spells_by_element", collection = ref(id = "indexes")),
            terms: "fire"
          }
        }
      ]
    },
    {
      value: ref(id = "181388642071085568", collection = ref(id = "spells", collection = ref(id = "collections"))),
      sources: [
        {
          @set = {
            match: ref(id = "spells_by_element", collection = ref(id = "indexes")),
            terms: "fire"
          }
        },
        {
          @set = {
            match: ref(id = "spells_by_element", collection = ref(id = "indexes")),
            terms: "water"
          }
        }
      ]
    },
    {
      value: ref(id = "181388642088911360", collection = ref(id = "spells", collection = ref(id = "collections"))),
      sources: [
        {
          @set = {
            match: ref(id = "spells_by_element", collection = ref(id = "indexes")),
            terms: "water"
          }
        }
      ]
    }
  ]
}
map[data:[
  map[value:{181388642046968320 0xc42024a960 <nil>} sources:[{map[match:{spells_by_element 0xc42024ab00 <nil>} terms:fire]}]]
  map[value:{181388642071085568 0xc42024ada0 <nil>} sources:[{map[terms:fire match:{spells_by_element 0xc42024af40 <nil>}]} {map[match:{spells_by_element 0xc42024b100 <nil>} terms:water]}]]
  map[value:{181388642088911360 0xc42024b3e0 <nil>} sources:[{map[match:{spells_by_element 0xc42024b580 <nil>} terms:water]}]]
]]
{
  "data": [
    {
      "value": { "@ref": "classes/spells/181388642046968320" },
      "sources": [
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "fire"
          }
        }
      ]
    },
    {
      "value": { "@ref": "classes/spells/181388642071085568" },
      "sources": [
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "fire"
          }
        },
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "water"
          }
        }
      ]
    },
    {
      "value": { "@ref": "classes/spells/181388642088911360" },
      "sources": [
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "water"
          }
        }
      ]
    }
  ]
}
{
  "data": [
    {
      "value": { "@ref": "classes/spells/181388642046968320" },
      "sources": [
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "fire"
          }
        }
      ]
    },
    {
      "value": { "@ref": "classes/spells/181388642071085568" },
      "sources": [
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "fire"
          }
        },
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "water"
          }
        }
      ]
    },
    {
      "value": { "@ref": "classes/spells/181388642088911360" },
      "sources": [
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "water"
          }
        }
      ]
    }
  ]
}
{
  "data": [
    {
      "value": { "@ref": "classes/spells/181388642046968320" },
      "sources": [
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "fire"
          }
        }
      ]
    },
    {
      "value": { "@ref": "classes/spells/181388642071085568" },
      "sources": [
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "fire"
          }
        },
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "water"
          }
        }
      ]
    },
    {
      "value": { "@ref": "classes/spells/181388642088911360" },
      "sources": [
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "water"
          }
        }
      ]
    }
  ]
}
{
  "data": [
    {
      "value": { "@ref": "classes/spells/181388642046968320" },
      "sources": [
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "fire"
          }
        }
      ]
    },
    {
      "value": { "@ref": "classes/spells/181388642071085568" },
      "sources": [
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "fire"
          }
        },
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "water"
          }
        }
      ]
    },
    {
      "value": { "@ref": "classes/spells/181388642088911360" },
      "sources": [
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "water"
          }
        }
      ]
    }
  ]
}
{ data:
   [ { value: Ref(id=181388642046968320, collection=Ref(id=spells, collection=Ref(id=collections))),
       sources: [Object] },
     { value: Ref(id=181388642071085568, collection=Ref(id=spells, collection=Ref(id=collections))),
       sources: [Object] },
     { value: Ref(id=181388642088911360, collection=Ref(id=spells, collection=Ref(id=collections))),
       sources: [Object] } ] }

The following query returns the same set of results as the first "spells" query, but by setting the events option to true, the events associated with each item in the set are included in the result:

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

fmt.Println(result)
client.query(
  Paginate(
    Union(
      Match(Index("spells_by_element"), "fire"),
      Match(Index("spells_by_element"), "water")),
    events = true))
client.query(
  q.paginate(
    q.union(
      q.match(q.index("spells_by_element"), "fire"),
      q.match(q.index("spells_by_element"), "water")
    ),
    events=True
  ))
$client.query do
  paginate union(match(index('spells_by_element'), 'fire'),
                 match(index('spells_by_element'), 'water')),
           events: true
end
client.query(
    Paginate(
        Union(
            Match(
                index: Index("spells_by_element"),
                terms: "fire"
            ),
            Match(
                index: Index("spells_by_element"),
                terms: "water"
            )
        ),
        events: true
    )
)
client.query(
  q.Paginate(
    q.Union(
      q.Match(q.Index('spells_by_element'), 'fire'),
      q.Match(q.Index('spells_by_element'), 'water'),
    ),
    { events: true },
  )
)
.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" }
      },
      {
        "ts": 1509244539235128,
        "action": "create",
        "resource": { "@ref": "classes/spells/181388642088911360" }
      }
    ]
  }
}
{
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    },
    {
      "ts": 1509244539235128,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642088911360" }
    }
  ]
}
{
  data: [
    {
      ts: 1526663274438247,
      action: "add",
      document: ref(id = "181388642071085568", collection = ref(id = "spells", collection = ref(id = "collections")))
    },
    {
      ts: 1526663274504812,
      action: "add",
      document: ref(id = "181388642046968320", collection = ref(id = "spells", collection = ref(id = "collections")))
    },
    {
      ts: 1526663274516453,
      action: "add",
      document: ref(id = "181388642088911360", collection = ref(id = "spells", collection = ref(id = "collections")))
    }
  ]
}
map[data:[
  map[document:{181388642046968320 0xc420205300 <nil>} action:add ts:1509244539203043]
  map[document:{181388642071085568 0xc4202055c0 <nil>} action:add ts:1509244539223511]
  map[document:{181388642088911360 0xc4202058a0 <nil>} action:add ts:1509244539235128]
]]
{
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    },
    {
      "ts": 1509244539235128,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642088911360" }
    }
  ]
}
{
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    },
    {
      "ts": 1509244539235128,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642088911360" }
    }
  ]
}
{
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    },
    {
      "ts": 1509244539235128,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642088911360" }
    }
  ]
}
{
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    },
    {
      "ts": 1509244539235128,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642088911360" }
    }
  ]
}
{ data:
   [ { ts: 1509244539203043,
       create: 'add',
       document: Ref(id=181388642046968320, collection=Ref(id=spells, collection=Ref(id=collections))) },
     { ts: 1509244539203043,
       create: 'add',
       document: Ref(id=181388642071085568, collection=Ref(id=spells, collection=Ref(id=collections))) },
     { ts: 1509244539203043,
       create: 'add',
       document: Ref(id=181388642088911360, collection=Ref(id=spells, collection=Ref(id=collections))) } ] }

Was this article helpful?

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

Thank you for your feedback!