Update

Update( ref, param_object )
Update( ref, param_object )
Update( ref, param_object )
Update( ref param_object )
q.update( ref param_object )
update ref param_object
Update( ref param_object )
Update( ref, param_object )

Description

The update operation only modifies the specified fields in the instances pointed to by ref. Updates are partial, and only modify values that are specified in the param_object. Changes to scalar values and arrays are entirely replaced by the new data. Modifications to objects are merged. Setting a value to null completely removes the value. Fields in the instance not specified in the param_object are not modified.

Parameters

Argument Type Definition and Requirements

ref

Reference

A reference type containing the instance 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 instance’s user data to be modified.

credentials

Object

The instance’s credentials to be modified.

delegates

Object

The instance’s delegates to be modified.

Returns

An object containing the metadata about the update operations.

Field Name Field Type Definition and Requirements

ref

Reference

The reference which identifies the instance just updated.

data

Object

A copy of the new instance data.

ts

Long

The timestamp associated with the removal of the data.

Examples

The query below updates the instance data by changing the name field to the value "Mountains’s Thunder" and removing the cost field from the instance. All other fields in the instance remain unchanged.

curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "update": { "@ref": "classes/spells/181388642581742080" },
          "params": {
            "object": {
              "data": {
                "object": { "name": "Mountain's Thunder", "cost": null }
              }
            }
          }
        }'
client.Query(
  Update(
    Ref("classes/spells/181388642581742080"),
    Obj("data", Obj("name", "Mountain's Thunder", "cost", Null()))));
System.out.println(
    client.query(
        Update(
           Ref(Class("spells"), Value(181388642581742080L)),
           Obj(
              "data", Obj(
                  "name", Value("Mountain's Thunder"),
                  "cost", Null()
              )
           )
        )
    ).get());
result, _ := client.Query(
    f.Update(
        f.RefClass(f.Class("spells"), "181388642581742080"),
        f.Obj{
            "data": f.Obj{"name": "Mountain's Thunder", "cost": f.Null()},
        },
    ),
)

fmt.Println(result)
client.query(
  Update(
    Ref("classes/spells/181388642581742080"),
    Obj(
      "data" -> Obj("name" -> "Mountain's Thunder", "cost" -> Null())
    )))
client.query(
  q.update(
    Ref("classes/spells/181388642581742080"),
    {"data": {"name": "Mountain's Thunder", "cost": None}}
  ))
$client.query do
  update ref('classes/spells/181388642581742080'),
         data: { name: "Mountain's Thunder", cost: nil }
end
client.query(
    Update(
        ref: Ref("classes/spells/181388642581742080"),
        to: Obj(
            "data" => Obj("name" => "Mountain's Thunder", "cost" => nil)
        )
    )
)
client.query(q.Update(q.Ref(q.Class("spells"), "181388642581742080"), { data: {
  name: "Mountain's Thunder", cost: null } }))
.then((ret) => console.log(ret))
HTTP/1.1 200 OK
{
  "resource": {
    "ref": { "@ref": "classes/spells/181388642581742080" },
    "class": { "@ref": "classes/spells" },
    "ts": 1509244539727423,
    "data": { "name": "Mountain's Thunder", "element": "air" }
  }
}
{
  "ref": { "@ref": "classes/spells/181388642581742080" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539727423,
  "data": { "name": "Mountain's Thunder", "element": "air" }
}
{
   ref: ref(id = "181388642581742080", class = ref(id = "spells", class = ref(id = "classes"))),
   ts: 1526674566645179,
   data: {
     name: "Mountain's Thunder",
     element: "air"
   }
 }
map[ref:{181388642581742080 0xc420229300 <nil>} ts:1509244539727423 data:map[name:Mountain's Thunder element:air]]
{
  "ref": { "@ref": "classes/spells/181388642581742080" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539727423,
  "data": { "name": "Mountain's Thunder", "element": "air" }
}
{
  "ref": { "@ref": "classes/spells/181388642581742080" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539727423,
  "data": { "name": "Mountain's Thunder", "element": "air" }
}
{
  "ref": { "@ref": "classes/spells/181388642581742080" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539727423,
  "data": { "name": "Mountain's Thunder", "element": "air" }
}
{
  "ref": { "@ref": "classes/spells/181388642581742080" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539727423,
  "data": { "name": "Mountain's Thunder", "element": "air" }
}
{ ref:
   Ref(id=181388642581742080, class=Ref(id=spells, class=Ref(id=classes))),
  ts: 1527276015058883,
  data: { name: 'Mountain\'s Thunder', element: [ 'air' ] } }

Was this article helpful?

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

Thank you for your feedback!