replace()

Replace the existing fields with the provided fields.

Signature

replace(object: {*: Any}): CollectionDef

Description

The replace() method replaces the collection fields with the provided object.

You can’t replace a collection’s definition and write to documents in the collection in the same query. Use separate queries instead.

Parameters

Parameter Type Required Description

object

Object

Yes

Replacement Collection fields.

Return value

Type Description

CollectionDef

Collection with replaced fields.

Examples

  1. View the current document:

    Customer.byId('387120252471738436')
    {
      id: "387120252471738436",
      coll: Customer,
      ts: Time("2024-01-16T22:51:32.170Z"),
      firstName: "A",
      lastName: "Appleseed"
    }
  2. Replace the current document fields:

    Customer.byId('387120252471738436')!.replace({identifier: "00123"})
    {
      id: "387120252471738436",
      coll: Customer,
      ts: Time("2024-01-16T22:56:15.825Z"),
      identifier: "00123"
    }

See also

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!