MongoDB vs SurrealDB: Why I'm Switching

Complete comparison of MongoDB vs SurrealDB for modern applications. Learn about SQL-like queries, built-in RBAC, realtime subscriptions, vector support, and why SurrealDB might be better for your next project. Includes Docker setup examples and migration guide.

Michal Szajnecki
Michal Szajnecki
Jan 15, 20258 min read
MongoDB vs SurrealDB: Why I'm Switching

I started a sprint to ship four products in the next 60 days. To do that, I need a reliable database that won't slow down my progress with MVPs. So far, every prototype was powered by MongoDB, but quite often I hit a wall of small limitations. Like the need for transactions on a single-node database, or SQL-like queries that I can easily write. This comprehensive MongoDB vs SurrealDB comparison is part of my decision journal before choosing the production database engine. Whether you're evaluating databases for a new project, dealing with MongoDB limitations, or exploring modern database alternatives, this article provides practical insights, code examples, and real-world considerations.

MongoDB: What Made Me Love It (Pros and Cons)

  • Prototyping Speed: I could easily reshape my database without writing migrations, sketching everything in real-time.
  • Ecosystem: Everything is mature; there are tons of examples and battle-tested solutions.
  • Scalability: If I ever hit a jackpot with my app, I know I can scale horizontally without major rewrites.
  • Team Familiarity: Everyone I collaborate with has at least some MongoDB knowledge.

My Pain Points from Last Year

  • Single-node ACID Needs: Doing transactions on a single node is still hacky, and I don't want it to be like that.
  • Complex Queries: Simple queries are simple. But when we enter the field of aggregation, the whole code feels like an application on its own.
  • Ops Overhead: Scripted backups, database replication, and the whole ops stuff takes time to implement and maintain. I wonder if there's some built-in alternative.

5 Things That I Look For

  1. Setup Simplicity — I want it fully contained in a single Docker image.
  2. Clear Queries — I want clear, preferably SQL-like queries with joins.
  3. Simple RBAC — Record-level RBAC and scopes without custom middleware.
  4. Realtime + Vector Readiness — WebSocket subscriptions and VECTOR type out of the box.
  5. Indie Friendly — Self-hostable, predictable (low) costs, no vendor lock-in.

The result of my search pointed me towards SurrealDB.

Why SurrealDB Aligns: Key Advantages

Setup Simplicity

  • SurrealDB offers an official Docker image, so you can launch a dev/POC instance with a single command, or use it in docker-compose alongside your app.
  • For testing or development, you can simply persist to a local file—no cluster, no embedded dependencies.
  • Access to the Surrealist admin panel out of the box by enabling it.
  • Single binary runs locally or in Docker image, on Coolify, or bare-metal VPS.

Example: Minimal docker-compose.yml for SurrealDB

services:
  surrealdb:
    image: surrealdb/surrealdb:latest
    command: start --auth --user root --pass supersecret file:/data/surreal.db
    ports:
      - "8000:8000"
    volumes:
      - surrealdb_data:/data
volumes:
  surrealdb_data:

You can now connect to ws://localhost:8000 using the credentials provided above.

Tip: You can also enable the Surrealist web UI by setting environment variables, e.g., add:

environment:
  - SURREALIST=true

Clear Queries

  • SurrealQL blends SQL syntax with graph semantics, so nested relations stay readable 1.
  • It's clearly cleaner than complex MongoDB queries.
  • I can even start schemaless while iterating, then switch to SCHEMAFULL to lock production models.

Example:

Suppose we want to get all active users and their posts (with a join). In MongoDB, this requires an aggregation pipeline with $lookup:

db.user.aggregate([
  { $match: { active: true } },
  {
    $lookup: {
      from: "posts",
      localField: "id",
      foreignField: "author_id",
      as: "posts",
    },
  },
  // Optionally unwind posts array if you want flat results
]);

SurrealDB Equivalent – Much Cleaner:

SELECT user.*, posts.* FROM user
JOIN posts ON user.id = posts.author_id
WHERE user.active = true;

Simple RBAC

  • DEFINE TABLE ... PERMISSIONS enforces row-level access by default 2.
  • Scopes manage end-user logins, so I can remove custom auth glue in backend services 3.
  • Row-based permissions are enforced without external middleware, reducing security bugs.
  • Permission logic is readable and declarative—closer to business rules than imperative code.
  • Supports field-level restrictions, so sensitive data exposure risk is reduced.
  • Auth scopes can be easily tied to JWTs/Sessions, simplifying federation and SSO scenarios.

Example:

DEFINE TABLE blog_post SCHEMAFULL
  PERMISSIONS
    FOR select WHERE user = $auth.id OR published = true,
    FOR create, update, delete WHERE user = $auth.id;

Future-Proofing

  • Native VECTOR support keeps AI/LLM experiments close to operational data 4.
  • Graph edges unlock richer relationships once products mature 5.
  • Built-in realtime subscriptions enable live queries and updates with no extra backend glue, so collaborative features (e.g., dashboards, in-app notifications) work out-of-the-box 6.

Indie Friendly: Self-Hosted Database Solution

  • Completely free for self-hosted, so there's no platform lock-in or vendor costs.
  • SurrealDB is written in Rust and designed for minimal resource usage, so my bill remains small.
  • Comes with a lot of tools built-in needed for MVPs.
  • Inherits a lot of MongoDB features that make prototyping simple.

My Current Evaluation Progress (Pre-Production)

Right now, I've tested every path where MongoDB failed me on a really small test project. So I can say for sure that SurrealDB looks promising. Also, for the past few weeks, it's been working without any hiccups on my VPS, consuming a minimal amount of resources. Backups are working, but I haven't tested the full catastrophic recovery workflow. Also, all tests were performed on small datasets or low-usage apps.

Plan for Now

  1. Design & Test Recovery — Finalize emergency recovery process, test it on a staging server with a reasonable dataset.
  2. Improvements — Gather results from step one, update workflows, and retry until results are acceptable.
  3. Implementation — Add SurrealDB to all projects, step-by-step.
  4. Monitor & Optimize — Benchmark, tune indexes, document runbooks, monitor everything, publish findings.

Risks & Unknowns That I'm Now Aware Of

  • Younger ecosystem means fewer battle-tested best practices. There's a reasonable chance that there's a problem with SurrealDB that I'm not aware of, which can derail my products.
  • Observability stack (metrics, traces) still needs validation. I haven't set this up, and I'm basing my opinions mainly on metrics from Coolify or Docker stats/logs.
  • Learning curve from Mongo shell syntax to SurrealQL. Seems simple right now, but there's a risk that I haven't seen something that can be misleading.
  • Need a contingency plan if a blocking feature gap appears mid-launch. This can be catastrophic, as I really want to use something other than MongoDB or PostgreSQL for my MVPs.

Frequently Asked Questions (FAQ)

What is SurrealDB?

SurrealDB is a modern database that combines document, graph, and relational data models. It offers SQL-like queries (SurrealQL), built-in realtime subscriptions, vector support for AI, and row-level security out of the box.

How does SurrealDB compare to MongoDB?

SurrealDB offers SQL-like queries instead of complex aggregation pipelines, built-in ACID transactions on single nodes, row-level RBAC without custom middleware, realtime subscriptions, and vector support. MongoDB has a more mature ecosystem and better horizontal scaling options.

Is SurrealDB production-ready?

SurrealDB is actively developed and used in production, but the ecosystem is younger than MongoDB. Evaluate based on your specific needs, especially if you require battle-tested solutions or extensive community support.

Can I use SurrealDB with Docker?

Yes, SurrealDB provides an official Docker image. You can run it with a single command or integrate it into docker-compose setups for development and production.

Does SurrealDB support transactions?

Yes, SurrealDB supports ACID transactions on single-node deployments, which is one of the key advantages over MongoDB for single-node setups.

What programming languages support SurrealDB?

SurrealDB has official clients for JavaScript/TypeScript, Python, Rust, Go, and more. It also supports REST and WebSocket APIs for any language.

Is SurrealDB free?

Yes, SurrealDB is completely free and open-source for self-hosted deployments. There are no vendor lock-ins or platform costs.

Can SurrealDB replace MongoDB?

It depends on your use case. SurrealDB is excellent for MVPs, applications needing SQL-like queries, realtime features, and vector search. MongoDB might be better for applications requiring extensive horizontal scaling or mature ecosystem tools.

References

  1. SurrealDB Documentation - SurrealQL Language Guide. Available at: https://surrealdb.com/docs/surrealql
  2. SurrealDB Documentation - Table Permissions and Access Control. Available at: https://surrealdb.com/docs/surrealql/statements/define/table
  3. SurrealDB Documentation - Scopes and Authentication. Available at: https://surrealdb.com/docs/surrealql/statements/define/scope
  4. SurrealDB Documentation - Vector Fields and AI Integration. Available at: https://surrealdb.com/docs/surrealql/statements/define/field
  5. SurrealDB Documentation - Data Models: Relations and Graph Edges. Available at: https://surrealdb.com/docs/surrealdb/models
  6. SurrealDB Blog - Realtime Magic with Live Queries. Available at: https://surrealdb.com/blog/unlocking-streaming-data-magic-with-surrealdb-live-queries-and-change-feeds
Michal Szajnecki

Michal Szajnecki

Share Article: