Events

Copied!
( input )

Description

The Events function returns a Set of events for the provided Reference. These events represent the history of the reference, and demonstrate when the reference was created, modified, or removed.

The kinds of events vary based on the kind of reference provided:

Singular references
  • create

  • delete

  • update

Set references
  • add

  • remove

Since documents are stored immutably within Fauna, events are stored as snapshots of the associated document. Directly manipulating document history, using the Insert and Remove functions, does not currently affect subsequent event snapshots.

Parameter

Parameter Type Definition and Requirements

input

A Set of References, or a singular Reference.

Returns

A Set containing the creation, modification, or deletion events related to the provided input. Each event in the set contains the following fields:

Field Name Field Type Definition and Requirements

action

The action applied to the instance during the event.

data

Optional: only provided for documents containing user-supplied data. The data involved in the event.

instance

The Reference identifies the document associated with the event.

ts

The timestamp, with microsecond resolution, associated with the event.

Examples

The following query fetches the events for a regular document:

Copied!
((('posts'), '233555580689580553'))
((("posts"), "233555580689580553"))
Query metrics:
  •    bytesIn:  67

  •   bytesOut: 149

  • computeOps:   1

  •    readOps:   0

  •   writeOps:   0

  •  readBytes:   0

  • writeBytes:   0

  •  queryTime: 6ms

  •    retries:   0

And again, using Paginate to see the details of each event:

Copied!
(((('posts'), '233555580689580553')))
{
  data: [
    {
      ts: 1624310406540000,
      action: 'create',
      document: (("posts"), "233555580689580553"),
      data: { title: 'What I had for breakfast ..' }
    },
    {
      ts: 1624310406640000,
      action: 'update',
      document: (("posts"), "233555580689580553"),
      data: { tags: [ 'eggs', 'toast' ] }
    },
    {
      ts: 1624310406660000,
      action: 'delete',
      document: (("posts"), "233555580689580553"),
      data: null
    }
  ]
}
Query metrics:
  •    bytesIn:  80

  •   bytesOut: 625

  • computeOps:   1

  •    readOps:   1

  •   writeOps:   0

  •  readBytes: 302

  • writeBytes:   0

  •  queryTime: 6ms

  •    retries:   0

The following query fetches the events while using Singleton:

Copied!
(
  (
    ((('posts'), '233555580689580553'))
  )
)
{
  data: [
    {
      ts: 1624310406540000,
      action: 'add',
      document: (("posts"), "233555580689580553")
    },
    {
      ts: 1624310406660000,
      action: 'remove',
      document: (("posts"), "233555580689580553")
    }
  ]
}
Query metrics:
  •    bytesIn:  94

  •   bytesOut: 360

  • computeOps:   1

  •    readOps:   1

  •   writeOps:   0

  •  readBytes: 302

  • writeBytes:   0

  •  queryTime: 6ms

  •    retries:   0

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!