NewId

NewId()
NewId()
NewId()
NewId()
new_id()
NewId()
NewId()

Description

The NewId function produces a number which is guaranteed to be unique across all databases and is suitable for constructing the document ID part of a Reference.

Fauna’s document IDs are generated using the Twitter Snowflake algorithm. The IDs are based on time instead of being sequential, and are generally increasing. As such, the NewId function should not be used to generate random numbers.

FQL does not provide random number generation, as its operations attempt to be as deterministic as possible.

If you need a source of random numbers, your host language or browser can provide high-performance random number generation. Once you have generated a random number, you can then use it within your queries in deterministic fashion.

Parameters

None.

Returns

A unique numeric String.

Examples

The following query returns a unique string-encoded 64-bit integer:

try
{
    Value result = await client.Query(
        NewId()
    );
    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
StringV(280491725429932544)
result, err := client.Query(
	f.NewId())

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
280481920441123328
System.out.println(
    client.query(
        NewId()
    ).get());
"181388643266462208"
client.query(
  q.NewId()
)
.then((ret) => console.log(ret))
.catch((err) => console.error('Error: %s', err))
181388643266462208
result = client.query(
  q.new_id()
)
print(result)
"181388643266462208"
try {
  println(Await.result(
    client.query(NewId()),
    5.seconds
  ))
} catch {
  case unknown: Throwable => println("Error: " + unknown.getMessage())
}
"181388643266462208"
NewId()
'302044032378339840'
Query metrics:
  •    bytesIn:  15

  •   bytesOut:  33

  • computeOps:   1

  •    readOps:   0

  •   writeOps:   0

  •  readBytes:   0

  • writeBytes:   0

  •  queryTime: 2ms

  •    retries:   0

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve!
Visit Fauna's Discourse forums or email docs@fauna.com

Thank you for your feedback!