Generating refs?

Hey!

Disclaimer first: I’m aware that JS can’t handle 64 bit integers out of the box.

Fauna document ids are string-encoded 64-bit integers (see here). Can one be generated through fauna JavaScript driver (or something similar) in advance of, for example, creating a document?

What I mean in pseudo code:

// some magic to create the document id
const id = magick()

// then I could
faunaClient.query(
  Create(Ref(Collection('Foo'), id), {
    data: {
      bar: 'biz'
    }
  })
)

Hi @boojum - absolutely! In fact, you already have it correct as written.

For example, in the Fauna shell:

Create(
  Ref(Collection("SomeCollection"), "1234567890"), {
  data: { string: "some string" }
})

Sure, I get that I can supply my own id with the above. My question is: can I generate just the id. Without creating a document in Fauna. For example to store it in a variable for later use.

Just to be clear: I’m not asking if I can supply my own id - I know I can do that. I’m asking if Fauna JS driver can generate one for me without the need to create an actual document in the database.

For example:

const id = faunaClient.generateId()

console.log(id) // 327041507083158092

Yes, see the documentation for the NewId function: NewId :: Fauna Documentation

1 Like

You’re a scholar and a gentlemen sir! Thanks!

2 Likes

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