Skip to content

Stop choosing. SurrealDB launch week, 12-16 October

See what's coming
Course content preview

3: Using the ONLY keyword

SurrealDB returns an array of results by default. But in queries that return a single record, you can add ONLY to return the record itself instead of the record contained inside an array.

-- Return an array with one record inside
CREATE place;
-- Return one record
CREATE ONLY place;


Output · Query 1
[
  {
    id: place:hke4u4eqkm9lomnma9ac
  }
]
Output · Query 2
{
  id: place:8xi1lvtx785stp7lyy64
}


This is useful when working with the output of a query. Instead of needing to use [0] to pull out the first item at index 0, the output of the query itself is now just a single record.

It is also helpful when using one of the SDKs and you want a response that can be deserialised easily into a single object.

THE PLATFORM

Everything an application and its agents know. Five surfaces, one engine.

IN PRODUCTION

Trusted at scale. Samsung, Nvidia, Verizon, Tencent, and Walmart run on SurrealDB.

14,000+

Developers building on SurrealDB Cloud

4M+

Developers building on SurrealDB worldwide

FROM THE TEAMS

SurrealDB gives us a foundation where we can unify semantic search, knowledge graphs, and AI-driven decision making without stitching together multiple systems. Collapsing responsibility into SurrealDB has become our default engineering posture.
Justin Foley

VP of Engineering, Later

SurrealDB

The context and memory layer for AI agents

Database. Graphs, vectors, documents and relational data in one engine, in a single ACID transaction.
Agent Memory. Connects and retrieves context wherever your data lives, every fact carrying its source.
Cloud. Fully managed, in the cloud provider and region you choose.

Explore with AI

Copyright © 2026 SurrealDB Ltd. Registered in England and Wales. Company no. 13615201

Registered address: 3rd Floor 1 Ashley Road, Altrincham, Cheshire, WA14 2DT, United Kingdom

Trading address: Huckletree Oxford Circus, 213 Oxford Street, London, W1D 2LG, United Kingdom