How do I update an array item at a given index with the Update function?

I’m trying to update an item in a array nested in an object. I just can’t seem to figure it out. Seems like this is something simple that i’m missing.

Is it possible to access an array item with the Update function?

Given this data I would like to update bar at index 0 to baz:false.

doc:
data:{
    foo:"hello",
    bar:[{baz:true},{baz:false}],
    }
Query(
  Lambda(
    ["docRef", "index"],
        Update(Var("docRef"), {
          data: { bar[Var("index")]:{baz:true}}
    })
  )
)

This is what I originally thought it would be like.

Any help is very appreciated.

Hey !

I believe you would still need to read the data before updating & use a custom function to update the array. I used this one ReplaceAtIndex as an UDF.

Query(
  Lambda(
    ['docRef', 'index'],
    Update(
      Var('docRef'),
      Let(
        {
          currentBar: Select(['data', 'bar'], Get(Var('docRef')))
        },
        {
          bar: Call(Function('ReplaceAtIndex'), [Var('currentBar'), Var('index'), { baz: true }])
        }
      )
    )
)

Thanks!, I seemed to have got that working.