Serializing Cursors


I have an HTTP endpoint which returns the result of a paginate call.
I would like to somehow serialize the next cursor to a format that I can pass as a query string parameter in the URL of the next request.

My next cursor looks something like:

  Ref(Collection("posts"), "273622809807159820"),
  Ref(Collection("posts"), "273622809807159820")

I have tried to base64 encode it like this:

new Buffer(JSON.stringify(after)).toString('base64')

and decoding with:

JSON.parse(new Buffer(after, 'base64').toString('utf8'))

However, when I give the decoded array to my paginate call I get the following error:

Ref expected, Object provided.

Am I going about this in the best way?


You are very close :slight_smile: You need to use parseJSON from the FaunaDB JS driver when decoding. See this:


Brilliant thank you! Works perfectly!

I do feel a little dirty importing from an internal module… Probably worth thinking about exporting it in the actual module :slightly_smiling_face:

Agree, I have seen it requested multiple times before