Generated Values
Some functions mint a fresh value at write time instead of reading one. They work anywhere an expression is accepted (RETURN, SET) and - unlike ordinary functions - also as placeholders inside property maps: node and relationship CREATE, MERGE, and the document statements CREATE DOCUMENT / UPSERT DOCUMENT.
| Function | Produces | Access |
|---|---|---|
| randomUUID() | New UUID v4 string | editor / admin |
| uuid() | Alias of randomUUID() | editor / admin |
| timestamp() | Current epoch milliseconds (integer) | any role |
| datetime() | Current epoch milliseconds (integer, alias in property maps) | any role |
| point({x, y}) | Spatial point value | any role |
Anvil assigns every node an internal numeric id(n), but that is a storage handle - it is not stable across export/import and is reused after deletes. Use randomUUID() for application-level identity, and add a UNIQUE INDEX on the property you store it in.
Graph Examples
// Ask the server for a UUID
RETURN randomUUID() AS id
// New node with a generated id and creation time
CREATE (r:Request {id: randomUUID(), createdAt: timestamp(), status: "open"})
RETURN r.id
// Relationship properties work the same way
MATCH (a:User {name: "alice"}), (p:Project {name: "anvil"})
CREATE (a)-[m:MEMBER_OF {id: uuid(), since: timestamp()}]->(p)
RETURN m.id
// MERGE: only stamp the id when the node is first created
MERGE (u:User {email: "a@example.com"})
ON CREATE SET u.id = randomUUID(), u.createdAt = timestamp()
// Backfill ids on existing nodes
MATCH (n:Legacy) SET n.id = uuid()Document Examples
The same placeholders evaluate inside document bodies. The stored document contains the generated value, not the call.
CREATE COLLECTION orders
// Server generates the id and timestamp at insert time
CREATE DOCUMENT IN orders order-1001 {
id: randomUUID(),
placedAt: timestamp(),
total: 79.90
}
UPSERT DOCUMENT IN orders order-1002 {id: uuid(), placedAt: datetime(), total: 12.50}
MATCH DOCUMENT d IN orders RETURN d.id, d.placedAt
// "1f8f7a2e-9c1b-4e0d-8a53-1c2d3e4f5a6b", 1787755364517Reserving a UUID over REST
Applications that need an id before writing (optimistic UI, client-side references, multi-step workflows) can ask the server for one. Anvil mints a UUID and locks it for 5 minutes: a reservation document in system.uuid_reservations, keyed by the UUID itself, records who took it and guarantees the same UUID is never handed out twice while reserved.
POST /db/uuid
Authorization: Bearer <token with editor or admin role>
// 200 OK
{
"uuid": "69020345-440c-4135-baa0-79c36add216d",
"expiresAt": 1787755664398,
"ttlSeconds": 300
}curl -X POST https://your-server:7474/db/uuid \ -H "authorization: Bearer $TOKEN"
Access Control
Minting identifiers is a write-adjacent operation, so randomUUID() / uuid() and POST /db/uuid require the editor or admin role - in any context, including a plain RETURN. A reader calling them gets randomUUID() requires write access (editor or admin role) (the REST endpoint answers 403). timestamp() and datetime() stay available to every role.