NewId

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

Description

This NewId function produces a unique number. This number is guaranteed to be unique across the entire cluster and once generated is never generated a second time. This identifier is suitable for constructing the id part of a reference.

Fauna’s numeric 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 numeric string:

client.Query(
    NewId()
);
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"
client.query(NewId())
"181388643266462208"

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!