RavenDB vs MongoDB

RavenDB reduces work

MongoDB creates it

A Powerful, Secure, and Easy-to-Use NoSQL Database.

RavenDB

Why choose

RavenDB over MongoDB

image of a rocket from a box

Great default experience

  • Indexes are created automatically.

  • Certificate based security out of the box.

  • Simple installation defaults mean less configuration later.

image of a rocket from a box

Handles the complexity of data management

  • Intuitive SQL-like queries.

  • Standard JSON documents.

  • Server-side patching.

image of a rocket from a box

Scalable and performant

  • Queries are faster as they run on automatically created indexes, not raw data.

  • Multiple layers of client-side caching to make things ever faster.

  • Multi-master architecture makes choosing new cluster leaders instant when a node fails.

image of a rocket from a box

Great default experience

  • Indexes are created automatically.

  • Certificate based security out of the box.

  • Simple installation defaults mean less configuration later.

image of a rocket from a box

Handles the complexity of data management

  • Intuitive SQL-like queries.

  • Standard JSON documents.

  • Server-side patching.

image of a rocket from a box

Scalable and performant

  • Queries are faster as they run on automatically created indexes, not raw data.

  • Multiple layers of client-side caching to make things ever faster.

  • Multi-master architecture makes choosing new cluster leaders instant when a node fails.

RavenDB and MongoDB were both started around 2009 and on the surface, they are quite similar. Document databases using JSON with focus on performance, scalability and a modern approach for database design.

When you look beyond the surface, it turns out that they have very different design philosophies and vision about what a modern database should be. In this page, we'll discuss the differences between RavenDB and MongoDB, and their impact on your systems.

Full comparison

icon Design philosophies

Reduce complexity of working with data, at any scale.

RavenDB focuses heavily on making things easy for developers and operators. RavenDB takes it upon itself to handle the complexity of data management for you.

RavenDB takes the approach that you don't need an expert at hand.

A core tenet of RavenDB's design philosophy is that you should be focused on getting things done, and the database engine will do the Right Thing for you.

MongoDB

Backend for extremely large-scale, cloud-based systems.

MongoDB focuses on enterprise solutions with high configurability and a high degree of flexibility, aiming to provide an answer to almost any scenario.

The drawback of this approach is that to operate a MongoDB database properly, you need a high degree of dedicated expertise to achieve good results.

For that reason, MongoDB recommends MongoDB Atlas (the cloud-hosted version) instead of running MongoDB directly.

Queries

icon The first query

from Orders
where ShipTo.City = 'London'

RavenDB uses an SQL-like language, intended to be familiar and intuitive for everyone. The query language was extended with document operations while keeping the ease of use and familiarity of SQL.

MongoDB
db.Orders.find({
"ShipTo.City": "London"
})

MongoDB queries are using a JSON-based format specific to the database. You'll need to familiarize yourself with the language to effectively use MongoDB.

blue fire iconEfficient queries

No action is required on your part to ensure that the query will run fast.

The RavenDB query optimizer selects the best index for your query automatically.

RavenDB
MongoDB
db.Orders.createIndex({
"ShipTo.City": 1
})

Requires careful index management for good performance.

With MongoDB, it is the responsibility of the developers (or database administrators) to create the right set of indexes for the queries.

This is a delicate and complex task that requires deep insight into both the system and the database internals. Without careful attention to detail, it is easy to end up with very slow queries.

Fixing these sorts of issues can be costly and complicated.

icon Queries evolution over time

Getting indexes right is a chore, but the real hurdle is when you need to evolve your system. When a new requirement is raised, how do we handle it?

Let's add sorting to the previous query, and see...

With RavenDB, you don't need deep insight into database internals to get good results. The database engine does everything for you.
from Orders
where ShipTo.City = 'London'
order by OrderedAt desc
limit 10

The work is completed

 // RavenDB adjusts itself for
// the new query on the fly
icon
MongoDB
db.Orders.find({
"ShipTo.City": "London"
}).sort({ "OrderedAt": -1})
.limit(10)

Some assembly required: you must manually create new compound indexes for added sorting or fields.

db.Orders.createIndex({
"ShipTo.City": 1,
"OrderedAt": -1
})
icon

icon Aggregating data

Aggregating data is a common operation in most systems. It is also one of the most expensive operations you can perform in a database, processing vast amounts of data.

Let's explore how each database handles aggregation.

from Orders
group by ShipTo.City
order by count() desc
select ShipTo.City, count()

The results will be near instantaneous, regardless of data size. RavenDB uses persistent Map-Reduce indexes to compute aggregations, so the computations happen in the background and are immediately available.

MongoDB
db.Orders.aggregate([{
"$group": {
"_id": "$ShipTo.City",
"Count": { "$sum": 1 }
}
},
{ "$sort": { "Count": -1 } },
{
"$project": {
"City": "$_id",
"Count": 1,
"_id": 0
}
}])

In MongoDB, this query runtime is proportional to the amount of records, even if you have the appropriate index. The more Orders you have, the more costly this query is.

RavenDB uses persistent Map-Reduce indexes to compute aggregations, so the computations happen in the background and are immediately available. When updates come in, RavenDB can apply the updates in an incremental manner.

icon Non-trivial queries

We have looked at very simple queries so far.

Let's see what happens as the application evolves and we look at more complex scenarios.

from Orders
where (ShipTo.City = 'London' or
ShipTo.Country = 'Narnia')
and OrderedAt between $weekAgo and
$today
and Status in ('Ready', 'Pending')
order by Total desc
limit 10

Queries are natural to read and easy to write, even as the queries grow more complex.

MongoDB
db.Orders.find({
$or: [
{ "ShipTo.City": "London" },
{ "ShipTo.Country": "Narnia" }
],
"OrderedAt": {
$gte: _weekAgo
$lte: _today
},
"Status": { $in: ["Ready", "Pending"] }
})
.sort({ Total: -1 })
.limit(10)

Queries quickly become unwieldy to manage except for the most trivial of queries. MongoDB often uses just a single index for the query, and documentation recommends against relying on multi-index optimization.

RavenDB queries are meant to be written by developers, and it's the database engine's responsibility to get them running fast.

MongoDB, beyond the more complex challenge, offers additional challenges. The query above touches several fields in the document.

Even if you created the right indexes, MongoDB will often use just a single index for the query. MongoDB's query optimizer is occasionally able to use multiple indexes to optimize a query, but MongoDB documentation recommends against relying on this behavior.

Indexes

Indexes allow a database engine to answer your queries in milliseconds instead of hours. RavenDB and MongoDB both use indexes to speed up queries, but there are a lot of differences between them.

RavenDB
RavenDB

Auto indexing

Expertise level: None, fully automated. An optimizer monitors queries and creates/removes indexes based on actual usage. No query is run without an index supporting it.

MongoDB

Expertise level: High, manual operation only. Depends on the DBA to manage the set of indexes.

icon Indexes performance & scalability

Processes indexing in the background; writes complete successfully without waiting. Supports any number of indexes (hundreds) without performance issues.

MongoDB

Indexes are processed as part of the write operation. More indexes = slower writes. Hard limit of 64 indexes per collection.

icon Index flexibility & usability

The manner in which each database can use its indexes is very different. Consider the following queries, common when users can choose their own sorting criteria.

The more indexes you have, the more work the database has to do. RavenDB can use a single index for many types of queries. MongoDB requires separate indexes for each task.
from Employees
order by LastName, FirstName
from Employees
order by LastName desc, FirstName

A single index can be used for many different queries. Any field in the index can be queried and sorted individually or in combination.

MongoDB
db.Employees.find()
.sort({ LastName: 1,
FirstName: 1 })
db.Employees.find()
.sort({ LastName: -1,
FirstName: 1 })

Sort order matters. A simple change in sort direction can force a full collection scan. Separate indexes are often required for each specific sort/query task.

db.Employees.createIndex({
LastName: 1, FirstName: 1 })
db.Employees.createIndex({
LastName: -1, FirstName: 1 })

RavenDB's indexes are built in such a way that a single index can be used for many different queries. This significantly reduces the resources that RavenDB needs to handle your workload.

Any field in the index can be queried and sorted individually or in combination with other index fields, meaning that a single index in RavenDB serves double or even triple duty compared to indexes in MongoDB (or even relational databases).

The structure of an index in MongoDB means that sort order matters. It's easy to write a query that uses an index and later make a simple change (such as the sort direction), which will force MongoDB to perform a full collection scan (a very slow operation).

As usual, a high degree of expertise, care, and attention is required to build effective applications using MongoDB.

icon Aggregations

  • RavenDB can move aggregation costs into the background, pre-computing the required information and massively speeding query time.
  • RavenDB's Map-Reduce indexes allow queries to return near-real-time data instantly, regardless of the data size involved.
MongoDB
  • MongoDB can utilize indexes during aggregation queries, but still needs to execute the aggregation at query time.
  • As the size of the data grows, the slower such queries become. Optimizing aggregation queries in MongoDB is a task for experts.

Full text search

  • Fully supported out of the box. No third party integration required.
from Posts
where search(Title, 'awesome')
  • Allows faceting, typo correction, highlights, and geo-spatial queries on existing nodes.
MongoDB

Basic support with many limitations. A typical solution requires integrating Elasticsearch. Atlas Search is not available for local deployments and incurs additional costs.

Vector Search

RavenDB treats vector search as a core capability. It uses its Corax search engine to handle high-dimensional vectors. Everything, from embedding generation to indexing and storage, happens inside the database itself.

MongoDB

MongoDB Atlas Vector Search is architecturally a separate service that runs alongside the core database. While it appears seamless via the API, it often involves dedicated Search Nodes in the cloud to handle the heavy lifting calculations.

Indexing computed values

  • RavenDB allows you to compute values during indexing, such as deriving the total value of an order by summing up its line items.
  • You can also integrate additional services, such as machine learning, during the indexing process.
  • RavenDB allows you to integrate with package managers to run custom code during the indexing process easily.
MongoDB
  • MongoDB has no support for computing values during the indexing process.
  • MongoDB recommends that you write computed fields directly into your documents (and ensure that they are updated on every write) instead of computing them at indexing time.

Operations

Securing your data

Your database contains the most valuable parts of your system. Protecting your data is a primary concern for your business.

RavenDB is secured by default and will refuse to run in unsecured mode. Your data is always going to be safe with RavenDB.

Secured by default. Refuses to run in an unsecured mode. Uses X.509 certificates and Zero Trust assumptions. If RavenDB runs, it is running securely.

MongoDB

Runs without any authentication by default. Setting up securely is complex and error-prone (100+ page document). Tens of thousands of instances have been affected by ransomware.

Distributed work and sharding

RavenDB and MongoDB can both run in a cluster, for scalability and high availability reasons. They take a very different approach on the actual mechanics of that.

RavenDB cluster is composed of homogenous and interchangeable nodes, all working together in a seamless manner.

Uses a multi-master model. Nodes are homogenous and interchangeable. For clustering purposes, the Raft consensus protocol is used. Sharding recommended beyond the 5 TB range.

MongoDB

Uses a single primary/multiple secondary model. Writes must go to the primary node. Complex components (config servers, routers, shards). Write scaling requires sharding at the 200 GB mark.

icon Failover & high availability

RavenDB and MongoDB both offer automatic failover when an error occurs. There are practical and important differences in the way the databases handle failure.

Node failure in RavenDB will result in an automatic and immediate switch to another node. Your applications will not notice any issues or problem.

Detects failure and selects a new leader in under one second. Clients failover transparently to the application.

MongoDB

Primary failure means write downtime (often 10+ seconds). Reads fail by default unless specific readConcern settings are used.

Patching documents & migration

Your applications grow over time, and data models change.

Let's see how each database allow you to modify your documents and evolve their structure.

from Employees as emp update {
emp.Name = emp.LastName +,
+ emp.FirstName;
delete emp.FirstName;
delete emp.LastName;
}

Allows modifying JSON documents en masse using simple JS scripts inside the database engine. No network traffic required.

MongoDB
// not possible, you need to write
// a full blown program for this

updateMany() is limited. Changes based on a document's own data (e.g., unifying name fields) require writing a separate program to load, modify, and save.

icon Operational overhead

RavenDB has an array of features explicitly aimed at making it easy to run your application in production with confidence and peace of mind. RavenDB actively tries to get out of your way.

Automatically caches all read operations. Saving data is ACID compliant. Built-in monitoring, alerts, and performance hints reduce the need for high expertise.

MongoDB

Leaves caching management to the user. Transactions are opt-in. Relies on administrators to manually analyze query patterns and optimize indexes.

Open source

Open Source project with an OSI-approved permissive license.

MongoDB

Changed license in 2018 to Source Available; no longer an Open Source project.

MongoDB was meant to be a backend database for a Platform as a Service product.

RavenDB was envisioned to be a database that lets developers get things done.

MongoDB was meant to be a backend database for a Platform as a Service product.

RavenDB was envisioned to be a database that lets developers get things done.

Oren Eini
RavenDB Founder and CEO
pic of Orenpic of Oren

Thousands of customers have chosen RavenDB

ToyotaToyota
Desoutter
trackmatictrackmatic
upapp
VerizonVerizon
Rakuten KoboRakuten Kobo
JetBrainsJetBrains
Capgemini
Medicaid
Insight
ParticularParticular
ESO
ConfigitConfigit
LuwareLuware
NimbleNimble
Incomm Incentives
Simple Store
Serverflex
Sparkling Logic
esignatur
View.DO
Starnet
Strife
Amberwood Trading
RavenDB was easier than MongoDB or CouchDB to set-up. The RQL also allowed us to use the same logic as we use with SQL when querying data.”
DPG Media
Ygor Castor
Software Architect
Read full case study
“As a document database it remains true to the core principles of these type of storage mechanisms. Somehow it managed to combine the best of relational databases with that of document databases.”
Hadi Hariri
VP of Developer Advocacy
JetBrains
“Considering how huge the amount of data sent back and forth in a single quote document is, the fact that RavenDB can store the entire document and continue to perform well is really impressive.”
Peter Tiedeman
Senior Principal Software Developer
Configit
“We take pain away from our users, and RavenDB takes pain away from us.”
Alan Doherty
Co-Founder
Serverflex
“A document database without querying power would have become a bottleneck. RavenDB gave us the querying power we needed without sacrificing the flexibility in the documents.”
Carlos Serrano
Co-Founder and CTO
Sparkling Logic
“Databases are scary. They hold your data. If something goes wrong, you are in trouble. Knowing how RavenDB works internally gives me a sense of peace that if I get into trouble, I know exactly what to do.”
Sarmaad Amin
Co-Founder
Simple Store
“RavenDB does everything I need, and a million times more.”
Jeremy Holt
CEO
Amberwood Trading
“We started with Mongo and tried to optimize our application code... We soon got to a point where we saw our database was being a bottleneck... We were definitely impressed by Raven's performance. It was a drastic improvement from Mongo's.”
IoT Bridge
Tyron Surajpal
IoT Bridge
Read full case study

See how we compare to other databases

“Under load, RavenDB matches or exceeds Couchbase performance at the 99.99 percentile with a third of the hardware resources. In the cloud this translates to 80% cost savings.”
Rakuten Kobo
Trevor Hunter
CTO of Rakuten Kobo
Read full case study

Get started in minutes

Download free and experience the difference for yourself.

RavenDB vs MongoDB - RavenDB NoSQL Database