Check out v4 of the Fauna CLI

v4 of the Fauna CLI is now in beta.

The new version introduces enhancements to the developer experience, including an improved authentication workflow. To get started, check out the CLI v4 quick start.

FQL cheat sheet

This page provides a quick reference of FQL properties and methods, grouped by functionality.

Array
Array.sequence()

Create an ordered Array of Numbers given start and end values.

array.length

The number of elements in the Array.

array.aggregate()

Aggregate all elements of an Array.

array.any()

Test if any element of an Array matches a provided predicate.

array.append()

Append a provided element to an Array.

array.at()

Get the Array element at a provided index.

array.concat()

Concatenate two Arrays.

array.distinct()

Get the unique elements of an Array.

array.drop()

Drop the first N elements of an Array.

array.entries()

Add the index to each element of an Array.

array.every()

Test if every element of an Array matches a provided predicate.

array.filter()

Filter an Array using a provided predicate.

array.first()

Get the first element of an Array.

array.firstWhere()

Get the first element of an Array that matches a provided predicate.

array.flatMap()

Apply a provided function to each Array element and flatten the resulting Array by one level.

array.flatten()

Flatten an Array by one level.

array.fold()

Reduce the Array to a single, accumulated value by applying a provided function to each element. Iterates through elements from left to right. Uses a provided seed as the initial value.

array.foldRight()

Reduce an Array to a single, accumulated value by applying a provided function to each element. Iterates through elements from right to left. Uses a provided seed as the initial value.

array.forEach()

Run a provided function on each element of an Array. Can perform writes.

array.includes()

Test if the Array includes a provided element.

array.indexOf()

Get the index of the first Array element that matches a provided value.

array.indexWhere()

Get the index of the first Array element that matches a provided predicate.

array.isEmpty()

Test if an Array is empty.

array.last()

Get the last element of an Array.

array.lastIndexOf()

Get the index of the last Array element that matches a provided value.

array.lastIndexWhere()

Get the index of the last Array element that matches a provided predicate.

array.lastWhere()

Get the last element of an Array that matches a provided predicate.

array.map()

Apply a provided function to each element of an Array. Can’t perform writes.

array.nonEmpty()

Test if an Array is not empty.

array.order()

Sort an Array's elements.

array.prepend()

Prepend an element to an Array.

array.reduce()

Reduce an Array to a single, accumulated value by applying a provided function to each element. Iterates through elements from left to right. Uses the first element as the initial value.

array.reduceRight()

Reduce an Array to a single, accumulated value by applying a provided function to each element. Iterates through elements from right to left. Uses the first element as the initial value.

array.reverse()

Reverse the order of an Array's elements.

array.slice()

Get a subset of an Array's elements based on provided indexes.

array.take()

Get the first N elements of an Array.

array.toSet()

Convert an Array to a Set.

array.toString()

Convert an Array to a String.

array.where()

Get the elements of an Array that match a provided predicate.

Collection
collection.definition

Get a collection definition, represented as a Collection document with the CollectionDef type.

Collection()

Access a collection by its name.

Collection.all()

Get a Set of all collection definitions.

Collection.byName()

Get a collection definitions by its name.

Collection.create()

Create a collection.

Collection.firstWhere()

Get the first collection definition that matches a provided predicate.

Collection.toString()

Get "Collection" as a String.

Collection.where()

Get a Set of collection definitions that match a provided predicate.

collectionDef.delete()

Delete a collection.

collectionDef.exists()

Test if a collection exists.

collectionDef.replace()

Replaces a collection definition.

collectionDef.update()

Update a collection definition.

collection.all()

Get a Set of all documents in a collection.

collection.byId()

Get a collection document by its document id.

collection.create()

Create a collection document.

collection.firstWhere()

Get the first collection document that matches a provided predicate.

collection.indexName()

Call an index as a method to get a Set of matching collection documents.

collection.where()

Get a Set of collection documents that match a provided predicate.

Credential
Credential.all()

Get a Set of all credentials.

Credential.byDocument()

Get a credential by its identity document.

Credential.byId()

Get a credential by its document id.

Credential.create()

Create a credential.

Credential.firstWhere()

Get the first credential that matches a provided predicate.

Credential.toString()

Get "Credential" as a String.

Credential.where()

Get a Set of credentials that match a provided predicate.

credential.delete()

Delete a credential.

credential.exists()

Test if a credential exists.

credential.login()

Create a token for a provided credential and its password.

credential.replace()

Replace a credential.

credential.update()

Update a credential.

credential.verify()

Test whether a provided password is valid for a credential.

Database
Database.all()

Get a Set of all child databases nested directly under the database.

Database.byName()

Get a child database by its name.

Database.create()

Create a child database.

Database.firstWhere()

Get the first child database document that matches a provided predicate.

Database.toString()

Get "Database" as a String.

Database.where()

Get a Set of child databases that match a provided predicate.

database.delete()

Deletes a child database.

database.exists()

Test if a child database exists.

database.replace()

Replace a child database's metadata and settings.

database.update()

Update a child database's metadata and settings.

Date
dayOfMonth

Get the day of the month from a Date.

dayOfWeek

Get the day of the week from a Date.

dayOfYear

Get the day of the year from a Date.

month

Get the month of a Date.

year

Get the year of a Date.

Date()

Construct a Date from a ISO 8601 date String.

Date.fromString()

Construct a Date from a date String.

Date.today()

Get the current UTC Date.

date.add()

Add number of days to a Date.

date.difference()

Get the difference between two Dates.

date.subtract()

Subtract number of days from a Date.

date.toString()

Convert a Date to a String.

EventSource
eventSource.map()

Apply an anonymous function to each element of an event source's tracked Set.

eventSource.toString()

Get "[event source]" as a string.

eventSource.where()

Create an event source that emits events for a subset of another event source’s tracked Set.

Global functions
abort()

End the current query and return an abort error with a user-defined abort value.

dbg()

Output a debug message in the query summary and return the message in the query results.

ID()

Create a valid ID

log()

Output a log message in the query summary and return null.

newId()

Get a unique string-encoded 64-bit integer.

Key
Key.all()

Get a Set of all keys.

Key.byId()

Get a key by its document id.

Key.create()

Create a key.

Key.firstWhere()

Get the first key that matches a provided predicate.

Key.toString()

Get "Key" as a String.

Key.where()

Get a Set of keys that match a provided predicate.

key.delete()

Delete a key.

key.exists()

Test if a key exists.

key.replace()

Replace a key.

key.update()

Update a key.

Math
Math.E

Get the Euler’s number mathematical constant (℮).

Math.Infinity

String value representing infinity.

Math.NaN

Value representing Not-a-Number.

Math.PI

Get the mathematical constant pi (π).

Math.abs()

Get the absolute value of a Number.

Math.acos()

Get the inverse cosine in radians of a Number.

Math.asin()

Get the inverse sine in radians of a Number.

Math.atan()

Get the inverse tangent in radians of a Number.

Math.ceil()

Round up a Number.

Math.cos()

Get the cosine of a Number in radians.

Math.cosh()

Get the hyperbolic cosine of a Number.

Math.degrees()

Convert radians to degrees.

Math.exp()

Get the value of ℮ raised to the power of a Number.

Math.floor()

Round down a Number.

Math.hypot()

Get the hypotenuse of a right triangle.

Math.log()

Get the natural logarithm, base e, of a Number.

Math.log10()

Get the base 10 logarithm of a Number.

Math.max()

Get the larger of two Numbers.

Math.mean()

Get the arithmetic mean of an Array or Set of Numbers.

Math.min()

Get the smaller of the input parameter Numbers.

Math.pow()

Get the value of a base raised to a power.

Math.radians()

Convert the value of a Number in degrees to radians.

Math.round()

Get the value of a Number rounded to the nearest integer.

Math.sign()

Get the sign of a Number.

Math.sin()

Get the sine of a Number in radians.

Math.sinh()

Get the hyperbolic sine of a Number.

Math.sqrt()

Get the square root of a Number.

Math.sum()

Get the sum of an Array or Set of Numbers.

Math.tan()

Get the tangent of a Number in radians.

Math.tanh()

Get the hyperbolic tangent of a Number.

Math.trunc()

Truncate a Number to a given precision.

Object
Object.assign()

Copies properties from a source Object to a destination Object.

Object.entries()

Convert an Object to an Array of key-value pairs.

Object.fromEntries()

Convert an Array of key-value pairs to an Object.

Object.hasPath()

Test if an Object has a property.

Object.keys()

Get an Object's top-level property keys as an Array.

Object.select()

Get an Object property’s value by its path.

Object.toString()

Convert an Object to a String.

Object.values()

Get an Object's property values as an Array.

Query
Query.identity()

Get the identity document for the query’s authentication token.

Query.isEnvProtected()

Test if the queried database is in protected mode.

Query.isEnvTypechecked()

Test if the queried database is typechecked.

Query.token()

Get the Token document or JWT payload for the query’s authentication secret.

Role
Role.all()

Get a Set of all user-defined roles.

Role.byName()

Get a user-defined role by its name.

Role.create()

Create a user-defined role.

Role.firstWhere()

Get the first user-defined role matching a provided predicate.

Role.toString()

Get "Role" as a String.

Role.where()

Get a Set of user-defined roles that match a provided predicate.

role.delete()

Delete a user-defined role.

role.exists()

Test if a user-defined role exists.

role.replace()

Replace a user-defined role.

role.update()

Update a user-defined role.

Schema
FQL.Schema.defForIdentifier()

Returns the definition for a user-defined collection or user-defined function (UDF) using the same rules as top-level identifier lookups.

Set
Set.paginate()

Get a page of paginated results using an after cursor.

Set.sequence()

Create an ordered Set of Numbers given start and end values.

Set.single()

Create a Set containing a single provided element.

set.aggregate()

Aggregate all elements of a Set.

set.any()

Test if any element of a Set matches a provided predicate.

set.changesOn()

Create an event source that tracks changes to specified document fields in a supported Set.

set.concat()

Concatenate two Sets.

set.count()

Get the number of elements in a Set.

set.distinct()

Get the unique elements of a Set.

set.drop()

Drop the first N elements of a Set.

set.eventsOn()

Create an event source that tracks changes to specified document fields in a supported Set.

set.eventSource()

Create an event source that tracks changes to documents in a supported Set.

set.every()

Test if every element of a Set matches a provided predicate.

set.first()

Get the first element of a Set.

set.firstWhere()

Get the first element of a Set that matches a provided predicate.

set.flatMap()

Apply a provided function to each Set element and flatten the resulting Set by one level.

set.fold()

Reduce the Set to a single, accumulated value by applying a provided function to each element. Iterates through elements from left to right. Uses a provided seed as the initial value.

set.foldRight()

Reduce a Set to a single, accumulated value by applying a provided function to each element. Iterates through elements from right to left. Uses a provided seed as the initial value.

set.forEach()

Run a provided function on each element of a Set. Can perform writes.

set.includes()

Test if the Set includes a provided element.

set.isEmpty()

Test if a Set is empty.

set.last()

Get the last element of a Set.

set.lastWhere()

Get the last element of a Set that matches a provided predicate.

set.map()

Apply a provided function to each element of a Set. Can’t perform writes.

set.nonEmpty()

Test if a Set is not empty.

set.order()

Sort a Set's elements.

set.pageSize()

Set the maximum elements per page in paginated results.

set.paginate()

Convert a Set to an Object with pagination.

set.reduce()

Reduce a Set to a single, accumulated value by applying a provided function to each element. Iterates through elements from left to right. Uses the first element as the initial value.

set.reduceRight()

Reduce a Set to a single, accumulated value by applying a provided function to each element. Iterates through elements from right to left. Uses the first element as the initial value.

set.reverse()

Reverse the order of a Set's elements.

set.take()

Get the first N elements of a Set.

set.toArray()

Convert a Set to an Array.

set.toStream()

Create an event source that tracks changes to documents in a supported Set.

set.toString()

Return the string "[set]".

set.where()

Get the elements of a Set that match a provided predicate.

String
string.length

Get a String's length.

string.at()

Get the character at a specified index of a String.

string.casefold()

Convert a String to lower case using a specified format.

string.concat()

Concatenate two Strings.

string.endsWith()

Test if a String ends with a provided suffix.

string.includes()

Test if a String includes a provided substring.

string.includesRegex()

Test if a String contains a substring that matches a provided regular expression.

string.indexOf()

Get the index of the first matching substring within a String.

string.indexOfRegex()

Get the index of the first substring matching a provided regular expression within a String.

string.insert()

Insert a substring into a String at a specified index.

string.lastIndexOf()

Get the index of the last matching substring within a String.

string.matches()

Get the substrings in a String that match a provided regular expression.

string.matchIndexes()

Get the indexes and substrings in a String that match a provided regular expression.

string.parseDouble()

Convert a String to a Double.

string.parseInt()

Convert a String to a Int.

string.parseLong()

Convert a String to a Long.

string.parseNumber()

Convert a String to a Number.

string.replace()

Replace a specified number of occurrences of a substring in a String.

string.replaceAll()

Replace all occurrences of a substring in a String.

string.replaceAllRegex()

Replace all occurrences of substrings matching a regular expression in a String.

string.replaceRegex()

Replace a specified number of occurrences of substrings matching a regular expression in a String.

string.slice()

Get the substring between two indexes of a String.

string.split()

Split a String at a provided separator.

string.splitAt()

Split a String at a provided index.

string.splitRegex()

Split a String using a provided regular expression.

string.startsWith()

Test if a String starts with a provided prefix.

string.toLowerCase()

Convert a String to lower case.

string.toString()

Get a String representation of the value.

string.toUpperCase()

Convert a String to upper case.

Time
dayOfMonth

Get the day of the month from a Time.

dayOfWeek

Get the day of the week from a Time.

dayOfYear

Get the day of the year from a Time.

hour

Get the hour of a Time.

minute

Get the minute of a Time.

month

Get the month of a Time.

second

Get the second of a Time.

year

Get the year of a Time.

Time()

Construct a Time from an ISO 8601 timestamp String.

Time.epoch()

Convert a Unix epoch timestamp to a Time.

Time.fromString()

Construct a Time from an ISO 8601 timestamp String.

Time.now()

Get the current UTC Time.

time.add()

Add a time interval to a Time.

time.difference()

Get the difference between two Times.

time.subtract()

Subtract a time interval from a Time.

time.toMicros()

Convert a Time to a Unix epoch timestamp in microseconds.

time.toMillis()

Convert a Time to a Unix epoch timestamp in milliseconds.

time.toSeconds()

Convert a Time to a Unix epoch timestamp in seconds.

time.toString()

Convert a Time to a String.

Token
Token.all()

Get a Set of all tokens.

Token.byDocument()

Get a token by its identity document.

Token.byId()

Get a token by its document id.

Token.create()

Create a token without a credential or related password.

Token.firstWhere()

Get the first token that matches a provided predicate.

Token.toString()

Get "Token" as a String.

Token.where()

Get a Set of tokens that match a provided predicate.

token.delete()

Delete a token.

token.exists()

Test if a token exists.

token.replace()

Replace a token.

token.update()

Update a token.

Transaction Time
TransactionTime()

Get the query transaction time.

TransactionTime.toString()

Get "[transaction time]" as a String.

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!