FaunaDB's documentation covers how to update a document, but their example assumes that I'll have the id
to pass into Ref
:
Ref(schema_ref, id)
client.query(
q.Update(
q.Ref(q.Collection('posts'), '192903209792046592'),
{ data: { text: "Example" },
)
)
However, I'm wondering if it's possible to update a document without knowing its id
. For instance, if I have a collection of users
, can I find a user by their email, and then update their record? I've tried this, but Fauna returns a 400 (Database Ref expected, String provided):
client
.query(
q.Update(
q.Match(
q.Index("users_by_email", "me@example.com")
),
{ name: "Em" }
)
)