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 )
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.
For performance, Databases, Collections, Functions, Indexes, Keys, and
Roles use a cache. When you use |
Parameters
Argument | Type | Definition and Requirements |
---|---|---|
|
A reference type containing the document that should be modified. |
|
|
An object that containing the document’s user data to be modified. See the following section for details. |
Returns
An object containing the metadata about the replace
operations.
Field Name | Field Type | Definition and Requirements |
---|---|---|
|
The reference that identifies the document just updated. |
|
|
A copy of the new document data. |
|
|
The timestamp, with microsecond resolution, of the document update. |
Examples
The following query updates the document by changing the name field to the value "Mountains’s Thunder", and removing the "cost" field from the document:
client.Query(
Replace(
Ref(Collection("spells"), "181388642581742080"),
Obj(
"data", Obj(
"name", "Mountain's Thunder",
"element", Arr("air", "earth")
)
)
)
);
ObjectV(ref: RefV(id = "181388642581742080", collection = RefV(id = "spells", collection = RefV(id = "collections"))),ts: LongV(1603756703860000),data: ObjectV(name: StringV(Mountain's Thunder),element: Arr(StringV(air), StringV(earth))))
result, err := client.Query(
f.Replace(
f.Ref(f.Collection("spells"), "181388642581742080"),
f.Obj{
"data": f.Obj{
"name": "Mountain's Thunder",
"element": f.Arr{"air", "earth"}}}))
if err != nil {
fmt.Fprintln(os.Stderr, err)
} else {
fmt.Println(result)
}
map[data:map[element:[air earth] name:Mountain's Thunder] ref:{181388642581742080 0xc000174180 0xc000174180 <nil>} ts:1603747275630000]
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"))
)
)
)
).get());
{ref: ref(id = "181388642581742080", collection = ref(id = "spells", collection = ref(id = "collections"))), ts: 1593467209080000, data: {name: "Mountain's Thunder", element: ["air", "earth"]}}
client.query(
q.Replace(
q.Ref(q.Collection('spells'), '181388642581742080'),
{
data: {
name: 'Mountain\'s Thunder',
element: ['air', 'earth'],
},
},
)
)
.then((ret) => console.log(ret))
.catch((err) => console.error('Error: %s', err))
{
ref: Ref(Collection("spells"), "181388642581742080"),
ts: 1592112569500000,
data: { name: "Mountain's Thunder", element: [ 'air', 'earth' ] }
}
result = client.query(
q.replace(
q.ref(q.collection("spells"), "181388642581742080"),
{
"data": {
"name": "Mountain's Thunder",
"element": ["air", "earth"]
}
}
)
)
print(result)
{'ref': Ref(id=181388642581742080, collection=Ref(id=spells, collection=Ref(id=collections))), 'ts': 1592874029090000, 'data': {'name': "Mountain's Thunder", 'element': ['air', 'earth']}}
client.query(
Replace(
Ref(Collection("spells"), "181388642581742080"),
Obj(
"data" -> Obj(
"name" -> "Mountain's Thunder",
"element" -> Arr("air", "earth")
)
)
)
)
{ref: ref(id = "181388642581742080", collection = ref(id = "spells", collection = ref(id = "collections"))), ts: 1594490272400000, data: {name: "Mountain's Thunder", element: ["air", "earth"]}}
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!