How to pass an object to a UDF

If I want to create an FQL for updating a collection I would like to just pass the object to the collection as not all fields may be updated. In JS this is easy as you can just pass the object to the update function but how would you do this for a UDF?

This is what I tried but it doesn’t seem like you can use Var for objects as parameters:

CreateFunction({
  name: 'update_user',
  body: Query(
    Lambda(
      ['id', 'updateBody'],
      Update(
        Ref(Collection('users'), Var('id')),
        Var('updateBody')
      )
    )
  )
})

You are wanting to update the document’s data.

CreateFunction({
  name: 'update_user',
  body: Query(
    Lambda(
      ['id', 'updateBody'],
      Update(
        Ref(Collection('users'), Var('id')),
        {
          data: Var('updateBody')
        }
      )
    )
  )
})

If you don’t include data, then you’re telling fauna to update some document metadata instead.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.