Get last events of a document


Making my way back to Fauna and it seems like I’ve been way too long away from FQL :sweat_smile:

How would you get the last events of a document ordered from most recent?

I’m starting from there:
Paginate(Ref(Collection("wallets"), "<id>"), { events: true })

Do I need to create an index on all events from my Collection(“wallets”) ?
(Also I’m not sure that this is possible)

Hi @gahabeen,

Something like that?

Select(['data'],Paginate(Events(Ref(Collection("wallets"), "<id>"))))

To get it in reversed order:

Reverse(Select(['data'],Paginate(Events(Ref(Collection("wallets"), "<id>")))))

Hope this answer your question.


Hey @Luigi_Servini,
Thanks for the quick feedback.

Your answer combined with a { before: null } to get the last one first and then using the cursors (before/after) to move backward or farward in time was what I was looking for!


Getting last events in descending order:

Reverse(Paginate(Events(Var('walletRef')), { before: null }))

Am I right @Luigi_Servini?

Hi @gahabeen,

Right, if you expect more than 64 results (by default Paginate() returns 64 entires) using

{before: null}

returns results with latest ts.