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());
"181388643266462208"
curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "new_id": null }'
HTTP/1.1 200 OK
{ "resource": "181388643266462208" }
result, _ := client.Query(f.NewId())

fmt.Println(result)
181388643266462208
System.out.println(client.query(NewId()).get());
"181388643266462208"
client.query(q.NewId())
.then((ret) => console.log(ret))
181388643266462208
client.query(q.new_id())
"181388643266462208"
client.query(NewId())
"181388643266462208"

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!