返回目录
开源项目文档办公类新手

SurrealDB:可扩展、分布式、协作的文档图数据库

SurrealDB 是一个用 Rust 构建的多模型数据库,统一文档、图、关系、时序、地理空间和键值数据模型,支持全文、向量和混合搜索,并具备实时、事件驱动和细粒度权限控制能力,可用于构建数据密集型系统、AI 代理数据层、知识图谱和实时应用。

0 次阅读2026/09/16 发布
SurrealDB:可扩展、分布式、协作的文档图数据库 来源图片

社区作者 · zZz

它解决什么问题

SurrealDB 是一个多模型数据库,使用 Rust 构建,旨在将多种数据模型统一到单个引擎中。它结合了文档、图、关系、时序、地理空间和键值数据类型,并具备强大的搜索和检索功能(全文、向量、混合)以及实时和事件驱动能力。SurrealDB 还可以作为后端即服务使用,因为它支持最终用户身份验证。由于它是单个 Rust 二进制文件,SurrealDB 可以嵌入式运行(应用内)、在浏览器中运行(通过 WebAssembly)、在边缘运行、作为单个后端节点自托管,或在云中的分布式集群中运行。

SurrealDB 适用于数据密集型系统,例如需要多种数据类型的应用程序、AI 代理的数据层、知识图谱、实时应用(如推荐引擎、欺诈检测系统)以及嵌入式/边缘系统。使用 SurrealDB,可以简化数据库和 API 基础设施,减少开发时间,并快速、经济高效地构建安全、高性能的应用。

核心特性包括:减少开发时间,简化数据库和 API 堆栈,无需大多数服务器端组件;原生多模型支持,通过 SurrealQL 提供文档、图、关系(强制模式和无模式)、时序、地理空间和检索(全文、向量、混合);实时协作 API 后端服务,既可作为数据库,也可作为 API 后端服务;支持多种查询语言,包括 SQL、GraphQL、ACID 事务、WebSocket 连接、结构化和非结构化数据、图查询、全文和向量索引以及地理空间查询;细粒度访问控制,提供基于行级权限的访问控制。

SurrealDB 可作为数据库服务器或嵌入式库使用;支持多行、多表 ACID 事务;支持单节点或高度可扩展的分布式模式;记录链接和定向类型图连接;存储结构化和非结构化数据;增量计算视图用于预计算高级分析;实时 API 层和内置安全权限;使用表、文档和图以任意方式存储和建模数据;为前端和后端开发提供简单的模式定义;直接从 Web 浏览器和客户端设备连接和查询;使用嵌入式 JavaScript 函数实现自定义高级功能;提供 MCP(Model Context Protocol)服务器用于 LLM 和 AI 代理集成。

文档资源包括:官方文档 https://surrealdb.com/docs,SurrealDB University https://surrealdb.com/learn,以及交互式书籍 Aeon's Surreal Renaissance https://surrealdb.com/learn/book。

适用对象:需要多模型数据库的开发者、构建 AI 代理数据层的团队、知识图谱开发者、实时应用(推荐引擎、欺诈检测)

— 本文由 AI 根据公开来源辅助整理,命令、版本与许可证请在使用前到原始页面复核。

安装 / 开始使用

For guidance on installation, development, deployment, and administration, take a look at the following resources:

Getting started Getting started with SurrealDB is as easy as starting up the SurrealDB database server, choosing your platform, and integrating its SDK into your code. You can easily get started with your platform of choice by reading one of our tutorials.

Server side code Client side apps SurrealDB Cloud SurrealDB is available as a managed cloud service . Forget about infrastructure operations, monitoring, backups or capacity planning.

SurrealDB Cloud allows you to focus on building great products using the power and flexibility of SurrealDB in just a few clicks. Grow from prototype to enterprise-scale.

The SurrealDB Cloud scalable architecture allows your database to evolve as your application grows, ensuring you are always ahead of demand. However if you want to deploy SurrealDB yourself, keep reading below.

Installation SurrealDB is designed to be simple to install and simple to run - using just one command from your terminal.

In addition to traditional installation, SurrealDB can be installed and run with HomeBrew, Docker, or using any other container orchestration tool such as Docker Compose, Docker Swarm, Rancher, or in Kubernetes.

Install on macOS The quickest way to get going with SurrealDB on macOS is to use Homebrew. This will install both the command-line tools, and the SurrealDB server as a single executable.

If you don't use Homebrew, follow the instructions for Linux below to install SurrealDB.

  • Documentation: https://surrealdb.com/docs
  • SurrealDB University: https://surrealdb.com/learn
  • Aeon's Surreal Renaissance (interactive book): https://surrealdb.com/learn/book
命令
brew install surrealdb/tap/surreal

If you want to test a version with the latest features, published every night, install the nightly version:

命令
brew install surrealdb/tap/surreal-nightly

Install on Linux The easiest and preferred way to get going with SurrealDB on Unix operating systems is to install and use the SurrealDB command-line tool. Run the following command in your terminal and follow the on-screen instructions.

命令
curl --proto ' =https ' --tlsv1.2 -sSf https://install.surrealdb.com | sh

If you want to run a beta release, before the next version is released, the beta version:

命令
curl --proto ' =https ' --tlsv1.2 -sSf https://install.surrealdb.com | sh -s -- --beta

If you want to test a version with the latest features, published every night, install the nightly version:

命令
curl --proto ' =https ' --tlsv1.2 -sSf https://install.surrealdb.com | sh -s -- --nightly

Install on Windows The easiest and preferred way to get going with SurrealDB on Windows is to install and use the SurrealDB command-line tool. Run the following command in your terminal and follow the on-screen instructions.

命令
iwr https: // windows.surrealdb.com - useb | iex

If you want to test a version with the latest features, published every night, install the nightly version: iex " & { $ ( irm https: // windows.surrealdb.com ) } -Nightly " Run using Docker

命令
Docker can be used to manage and run SurrealDB database instances without the need to install any command-line tools. The SurrealDB docker container contains the full command-line tools for importing and exporting data from a running server, or for running a server itself.
命令
docker run --rm --pull always --name surrealdb -p 8000:8000 surrealdb/surrealdb:latest start

For just getting started with a development server running in memory, you can pass the container a basic initialization to set the user and password as root and enable logging.

命令
docker run --rm --pull always --name surrealdb -p 8000:8000 surrealdb/surrealdb:latest start --log info --user root --pass root memory

Quick look With strongly-typed data types, data can be fully modelled right in the database. UPDATE person SET waist = < int > "34" , height = < float > 201 , score = < decimal > 0.3 + 0.3 + 0.3 + 0.

1 ; Store dynamically computed fields which are calculated when retrieved.

DEFINE FIELD can_drive ON TABLE person COMPUTED time::now () > birthday + 18y ; CREATE person SET birthday = d"2007-06-22" ; ; Easily work with unstructured or structured data, in schema-less or schema-full mode.

-- Create a schemafull table DEFINE TABLE user SCHEMAFULL ; -- Specify fields on the user table DEFINE FIELD name ON TABLE user TYPE object ; DEFINE FIELD name . first ON TABLE user TYPE string ; DEFINE FIELD name .

last ON TABLE user TYPE string ; DEFINE FIELD email ON TABLE user TYPE string ASSERT string::is_email ( $value ); -- Add a unique index on the email field preventing duplicate values DEFINE INDEX email ON TABLE user COLUMNS email UNIQUE ; -- Create a new event whenever a user changes their email address DEFINE EVENT email ON TABLE user WHEN $before .

email != $after . email THEN ( CREATE event SET user = $value , time = time::now (), value = $after . email , action = 'email_changed' ); Connect records together with fully directed graph edge connections.

-- Add a graph edge between user:tobie and article:surreal RELATE user : tobie -> write -> article : surreal

命令
SET time . written = time::now ()

; -- Add a graph edge between specific users and developers LET $from = ( SELECT users FROM company : surrealdb ); LET $devs = ( SELECT * FROM user WHERE tags CONTAINS 'developer' ); RELATE $from -> like -> $devs UNIQUE

命令
SET time . connected = time::now ()

; Query data flexibly with advanced expressions and graph queries.

-- Select a nested array, and filter based on an attribute SELECT emails [ WHERE active = true ] FROM person ; -- Select all 1st, 2nd, and 3rd level people who this specific person record knows, or likes, as separate outputs SELECT -> knows -> (?

AS f1 ) -> knows -> (? AS f2 ) -> ( knows , likes AS e3 WHERE influencer = true ) -> (?

AS f3 ) FROM person : tobie ; -- Select all person records (and their recipients), who have sent more than 5 emails SELECT * , -> sent -> email -> to -> person FROM person WHERE count (-> sent -> email ) > 5 ; -- Select other products purchased by people who purchased this laptop SELECT <- purchased <- person -> purchased -> product FROM product : laptop ; -- Select products purchased by people in the last 3 weeks who have purchased the same products that we purchased SELECT -> purchased -> product <- purchased <- person -> ( purchased WHERE created_at > time::now () - 3w ) -> product FROM person : tobie ; Store GeoJSON geographical data types, including points, lines and polygons.

UPDATE city : london SET centre = ( - 0.118092 , 51.509865 ), boundary = { type: "Polygon" , coordinates: [[ [ - 0.38314819 , 51.37692386 ], [ 0.1785278 , 51.37692386 ], [ 0.1785278 , 51.61460570 ], [ - 0.38314819 , 51.61460570 ], [ - 0.38314819 , 51.

37692386 ]

来源教程配图

SurrealDB Hero
配图 1 · SurrealDB Hero查看原图
SurrealDB Hero
配图 2 · SurrealDB Hero查看原图
Blog
配图 3 · Blog查看原图
Github
配图 4 · Github查看原图
LinkedIn
配图 5 · LinkedIn查看原图
X
配图 6 · X查看原图
YouTube
配图 7 · YouTube查看原图
Dev
配图 8 · Dev查看原图

适用场景

学习研究
开源项目实践