Using Reduce with Paginate with Index that returns multiple values

I have the following query:

Reduce(
  Lambda(
    [
      'accumulator',
      'value'
    ],
    Append(
      Get(Var(Select('ref', Var('value')))),
      Var('accumulator')
    )
  ),
  [],
  Paginate(
    Match(
      Index('eventsByVisibilityStatus'),
      'public'
    ),
    { size: 20 }
  )
)

This is the index:

CreateIndex({
  name: 'eventsByVisibilityStatus',
  source: Collection('_events'),
  terms: [
    { field: ['data', 'visibility'] }
  ],
  values: [
    { field: ['data', 'startDateTime'] },
    { field: ['data', 'endDateTime'] },
    { field: ['ref'] }
  ]
})

As you can see, the index returns an array of 3 items, how do I get those in the lambda callback of reduce? I have gone through trial and error but can’t get anything, unfortunately, there’s no console log in fauna shell so I can’t really inspect the items that are being passed around.

Okay, I just figured it out, the value in the callback is an array, so you access the values like an array.

1 Like

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