Updading an array in a document with values from another array

I’m migrating documents into Fauna that have an array if id’s [{id:1},{id:2},{id:3}].
These id’s corresponds to references from another collection, so I’m trying to set up a new array with Refs to do things the Fauna way.

I’m still very new, so confused over when to use a nested Map or if I should rather use Append.

This code throws a “Bad request” error.

let update = await client.query( 
        q.Let(
            {
              ref:q.Ref(q.Collection('users'), id),
              user:q.Get(q.Var('ref')),
              array:q.Select(['data','recos_received'],q.Var('user')),
            },
            q.Update(q.Var('ref'),{ 
                data: {
                   recos_receivedRefs: 
                      q.Map( q.Var('array'),  
                         q.Lambda('item', q.Ref(q.Collection('recos'), q.Var(['item', 'id']) ), ), 
                      )
                    , 
                } 

            })
        ),
    )

Thanks in advance for any pointers.

I’m not sure if this is the cleanest syntax, but this is how I managed to get it to work:
Selecting the array, then calling Map when writing to the new Array.

client.query( 
        q.Let(
            {
              ref:q.Ref(q.Collection('users'), id),
              user:q.Get(q.Var('ref')),
              data:q.Select('data',q.Var('user')),
              given:q.Select('recos_given',q.Var('data')),
            },
            q.Update(q.Var('ref'),{ 
                data: {
                    recos_givenRefs: 
                      q.Map( q.Var('given'),  
                         q.Lambda('item', q.Ref(q.Collection('recos'), q.Select('id',q.Var('item'))), ), 
                      )
                    , 
                } 
            
            })
        ),

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