token.replace()

Learn: Tokens

Replace a token.

Signature

replace(data: { *: Any }) => Token

Description

Replaces all fields in a token, represented as a Token document, with fields from a provided data object. Fields not present in the data object, excluding the id, coll, and ts metadata fields, are removed.

A token is a type of authentication secret used to provide identity-based access to a Fauna database. Fauna stores tokens as documents in the Token system collection.

Metadata fields

You can’t use this method to insert or edit the following metadata fields:

  • id

  • coll

  • ts

Parameters

Parameter Type Required Description

data

Object

Fields for the Token document. Fields not present, excluding the id, coll, and ts metadata fields, in the object are removed.

For supported document fields, see Token collection.

The object can’t include the following metadata fields:

  • id

  • coll

  • ts

Return value

Type Description

Token

Token document with replaced fields.

Examples

Token.byId("401670938431586381")!.replace({
  document: Customer.byId("222")
})
{
  id: "401670938431586381",
  coll: Token,
  ts: Time("2099-07-28T03:24:23.810Z"),
  document: Customer("222")
}
\