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 instance that will 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.

Returns

An object containing the metadata about the replace 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.

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("classes/spells/181388642581742080"),
    Obj(
      "data", Obj(
        "name", "Mountain's Thunder",
        "element", Arr("air", "earth"),
        "cost", 10
      )
    )));
System.out.println(
    client.query(
        Replace(
            Ref(Class("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.RefClass(f.Class("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("classes/spells/181388642581742080"),
    Obj(
      "data" -> Obj(
        "name" -> "Mountain's Thunder",
        "element" -> Arr("air", "earth"),
        "cost" -> 10
      )
    )))
client.query(
  q.replace(
    Ref("classes/spells/181388642581742080"),
    {
      "data": {
        "name": "Mountain's Thunder",
        "element": ["air", "earth"],
        "cost": 10
      }
    }
  ))
$client.query do
  replace ref('classes/spells/181388642581742080'),
          data: {
            name: "Mountain's Thunder",
            element: ['air', 'earth'],
            cost: 10
          }
end
client.query(
    Replace(
        ref: Ref("classes/spells/181388642581742080"),
        with: Obj(
            "data" => Obj(
                "name" => "Mountain's Thunder",
                "element" => Arr("air", "earth"),
                "cost" => 10
            )
        )
    )
)
client.query(q.Replace(q.Ref(q.Class("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", class = ref(id = "spells", class = ref(id = "classes"))),
  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, class=Ref(id=spells, class=Ref(id=classes))),
  ts: 1527275958680623,
  data:
   { name: 'Mountain\'s Thunder',
     element: [ 'air', 'earth' ],
     cost: 10 } }