Multi-document upsert?

@isle, you’re on the right track using q.Map.

Create and Replace expect the params object to also contain the data field. So do not Select it. Pass in fqlVar directly.

You want it to resolve into something like:

q.Create(q.Collection(‘products’), { data: { … } })

Does this work better?

function myUpsertFunction(fqlVar) {
Let(
  {
    match: q.Match(q.Index('productId'), q.Select(['data', 'productId'], fqlVar))
  },
  q.If(
    q.Exists(q.Var('match')),
    q.Replace(
      q.Select('ref', q.Get(q.Var('match'))),
      fqlVar
    ),
    q.Create(q.Collection('products'), fqlVar)
  )
)
}

Also

If for some reason you need to reduce read ops while doing this (like frequently upserting thousands at a time)