Struggle combining Update and Let in Function

I have been struggle to use “Update” with “Let” in Function, i just can’t get it to work, hope someone can give some pointer where i make a mistake.
here my code

but when i call, i got error.

Call(Function("dcreditV3"), "322834821982192204")

Error: [
  {
    "position": [ ],
    "code": "call error",
    "description": "Calling the function resulted in an error.",
    "cause": [
      {
        "position": [
          "expr",
          "update"
        ],
        "code": "invalid argument",
        "description": "Ref expected, Object provided."
      }
    ]
  }
]

When you call Update, you want to pass a Ref and not the object itself.

On line 5 in your FQL, you call Get(...), which resolves your reference to an object. If you remove the Get, you should get past that error.

Here is an example from the docs that shows the Update with the first argument being a Ref:

client.query(
  q.Update(
    q.Ref(q.Collection('spells'), '181388642581742080'),
    {
      data: {
        name: 'Mountain\'s Thunder',
        cost: null,
      },
    },
  )
)
3 Likes

Thank you for helping, i did remove Get, but still got an error.

Query(
Lambda(
“shipRef”,
Update(
Ref(Collection(“users”), Var(“shipRef”)),
Let(
{
shipDoc: Get(Var(“shipRef”)),
credit: Select([“data”, “credit”], Var(“shipDoc”))
},
{ data: { credit: Subtract(Var(“credit”), 1) } }
)
)
)
)

Call(Function(“dcreditV3”), “322834821982192204”)

Error: [
{
“position”: ,
“code”: “call error”,
“description”: “Calling the function resulted in an error.”,
“cause”: [
{
“position”: [
“expr”,
“params”,
“let”,
“shipDoc”,
“get”
],
“code”: “invalid argument”,
“description”: “Ref or Set expected, String provided.”
}
]
}
]

then after re-read your reply i notice, i just need to pass the Ref, not the object, so i make some adjustment now it work, thank you.

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