Replace

Replace( ref, param_object )
Replace( ref, param_object )
Replace( ref, param_object )
Replace( ref, param_object )
replace( ref, param_object )
replace ref param_object
Replace( ref, param_object )
Replace( ref, param_object )

Description

The replace operation substitutes the user data pointed to by the reference with the data contained in the param_object. Values not specified in the param_object are removed.

Parameters

Argument Type Definition and Requirements

ref

Reference

A reference type containing the document that should be modified.

param_object

Object

The param_object is an object which can contain many items.

param_object

Field Name Field Type Definition and Requirements

data

Object

The document’s user data to be modified.

Returns

An object containing the metadata about the replace operations.

Field Name Field Type Definition and Requirements

ref

Reference

The reference which identifies the document just updated.

data

Object

A copy of the new document data.

ts

Long

The timestamp associated with the removal of the data.

Examples

The query below updates the document by changing the name field to the value "Mountains’s Thunder" and removing the "cost" field from the document.

curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "replace": { "@ref": "classes/spells/181388642581742080" },
          "params": {
            "object": {
              "data": {
                "object": {
                  "name": "Mountain's Thunder",
                  "element": [ "air", "earth" ],
                  "cost": 10
                }
              }
            }
          }
        }'
client.Query(
  Replace(
    Ref(Collection("spells"), "181388642581742080"),
    Obj(
      "data", Obj(
        "name", "Mountain's Thunder",
        "element", Arr("air", "earth"),
        "cost", 10
      )
    )
  )
);
System.out.println(
    client.query(
        Replace(
            Ref(Collection("spells"), Value(181388642581742080L)),
            Obj(
               "data", Obj(
                          "name", Value("Mountain's Thunder"),
                           "element", Arr(Value("air"), Value("earth")),
                           "cost", Value(10)
                        )
             )
          )
    ).get());
result, _ := client.Query(
    f.Replace(
        f.RefCollection(f.Collection("spells"), "181388642581742080"),
        f.Obj{
            "data": f.Obj{
                "name": "Mountain's Thunder",
                "element": f.Arr{"air", "earth"},
                "cost": 10,
            },
        },
    ),
)

fmt.Println(result)
client.query(
  Replace(
    Ref(Collection("spells"), "181388642581742080"),
    Obj(
      "data" -> Obj(
        "name" -> "Mountain's Thunder",
        "element" -> Arr("air", "earth"),
        "cost" -> 10
      )
    )
  )
)
client.query(
  q.replace(
    q.ref(q.collection("spells"), "181388642581742080"),
    {
      "data": {
        "name": "Mountain's Thunder",
        "element": ["air", "earth"],
        "cost": 10
      }
    }
  )
)
$client.query do
  replace ref(collection('spells'), '181388642581742080'),
          data: {
            name: "Mountain's Thunder",
            element: ['air', 'earth'],
            cost: 10
          }
end
client.query(
    Replace(
        ref: Ref(Collection("spells"), "181388642581742080"),
        with: Obj(
            "data" => Obj(
                "name" => "Mountain's Thunder",
                "element" => Arr("air", "earth"),
                "cost" => 10
            )
        )
    )
)
client.query(
  q.Replace(
    q.Ref(q.Collection("spells"), "181388642581742080"),
    {
      data: {
        name: "Mountain's Thunder",
        element: ["air", "earth"],
        cost: 10,
      },
    },
  )
)
  .then((ret) => console.log(ret))
HTTP/1.1 200 OK
{
  "resource": {
    "ref": { "@ref": "classes/spells/181388642581742080" },
    "class": { "@ref": "classes/spells" },
    "ts": 1509244539764856,
    "data": {
      "name": "Mountain's Thunder",
      "element": [ "air", "earth" ],
      "cost": 10
    }
  }
}
{
  "ref": { "@ref": "classes/spells/181388642581742080" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539764856,
  "data": {
    "name": "Mountain's Thunder",
    "element": [ "air", "earth" ],
    "cost": 10
  }
}
{
  ref: ref(id = "181388642581742080", collection = ref(id = "spells", collection = ref(id = "collections"))),
  ts: 1526674566665295,
  data: {
    name: "Mountain's Thunder",
    element: ["air", "earth"],
    cost: 10
  }
}
map[ref:{181388642581742080 0xc420237480 <nil>} ts:1509244539764856 data:map[cost:10 element:[air earth] name:Mountain's Thunder]]
{
  "ref": { "@ref": "classes/spells/181388642581742080" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539764856,
  "data": {
    "name": "Mountain's Thunder",
    "element": [ "air", "earth" ],
    "cost": 10
  }
}
{
  "ref": { "@ref": "classes/spells/181388642581742080" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539764856,
  "data": {
    "name": "Mountain's Thunder",
    "element": [ "air", "earth" ],
    "cost": 10
  }
}
{
  "ref": { "@ref": "classes/spells/181388642581742080" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539764856,
  "data": {
    "name": "Mountain's Thunder",
    "element": [ "air", "earth" ],
    "cost": 10
  }
}
{
  "ref": { "@ref": "classes/spells/181388642581742080" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539764856,
  "data": {
    "name": "Mountain's Thunder",
    "element": [ "air", "earth" ],
    "cost": 10
  }
}
{ ref:
   Ref(id=181388642581742080, collection=Ref(id=spells, collection=Ref(id=collections))),
  ts: 1527275958680623,
  data:
   { name: 'Mountain\'s Thunder',
     element: [ 'air', 'earth' ],
     cost: 10 } }

Was this article helpful?

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

Thank you for your feedback!