🚀 Fauna Architectural Overview White Paper: Learn how Fauna's database engine scales with zero ops required
Download free
Fauna logo
Product
Solutions
Pricing
Resources
Company
Log InContact usStart for free
Fauna logo
Pricing
Customers
Log InContact usStart for free
© 0 Fauna, Inc. All Rights Reserved.

Related posts

Five DynamoDB limitations you should know before using itMongoDB Data API and HTTPS Endpoints Deprecation: Exploring Your OptionsComparing Fauna and DynamoDB

Start for free

Sign up and claim your forever-free Fauna account
Sign up and get started

Table of Contents

mongo

Overcoming MongoDB Limitations with Fauna

Kirk Kirkconnell |Oct 16th, 2024|

Categories:

Comparison
Developers are constantly seeking solutions that offer simplicity, scalability, and reliability. For many, MongoDB has long been a go-to when needing a NoSQL database with flexibility in data storage, but as applications grow in complexity, MongoDB’s limitations become harder to ignore. From managing schema validation inconsistencies to navigating its verbose Aggregation Framework, developers often write more code to maintain data integrity and optimize queries. Enter Fauna, a fully managed, truly serverless database designed to eliminate these pain points. With strict serializability, a more intuitive and powerful query language with native relational features, JSON documents with relationships like a relational database, and stronger built-in data consistency, Fauna offers a modern alternative. It helps reduce code bloat, speeds up developments, and lowers operational overhead. In this post, we’ll dive into five key differences between MongoDB and Fauna, as well as explore why Fauna might just be the database you didn’t know you needed.

MongoDB doesn’t have traversable relationships

MongoDB’s document-oriented data model doesn’t natively support complex traversable relationships (like joins in relational databases). While MongoDB provides manual alternatives such as embedding documents (denormalization) or performing multiple queries and handling relationships in the application logic, these approaches become complex and inefficient, especially for highly normalized data. The lack of native relationships often forces developers to rely on data duplication or quasi-join-like operations through MongoDB’s complex aggregation framework, which can be slow and cumbersome for complex queries. To put it differently, to get decent performance and scalability, you must sacrifice a data model that makes sense.
Yes, Mongoose ORM can help with this, but if there are 50 documents related to one document, even though this appears as one request in Mongoose, there are still 51 separate queries to MongoDB. Mongoose masks these queries from you, but your users will experience the inefficiencies.
Fauna, on the other hand, offers native support for relational (normalized) JSON documents, and the ability to traverse those relationships like a foreign key makes it easier to query deeply connected data sets without the need for complex joins, aggregation pipelines, or ORMs. In Fauna, if you have the same 50 documents related to one document I mentioned before, instead of 51 queries, it’s one query in Fauna. Fauna traverses document relationships to get the necessary information.

Schema validation approaches

MongoDB offers optional schema validation that's limited in utility. With validation enabled, MongoDB's schema validation system makes no guarantees about the structure of existing documents created or modified before the schema was added to the database. This forces developers to implement type-checking in their application code, increasing complexity. Moreover, MongoDB lacks built-in tooling to migrate from schemaless or an existing schema to the target schema with validation, much less migrate the data that doesn’t comply with the target schema. This leaves developers to handle schema changes and data migration on their own. Because MongoDB's schema validation system is not reliably consistent with the underlying data and lacks real support for migration, developers are no better off using it than before.
In contrast, Fauna’s schema validation, when enabled, is strictly enforced for the fields you define but allows some fields to be schemaless if desired. Documents with fields that don’t conform to the defined schema are not accepted, eliminating the need for additional checks in the application code. This ensures clean, consistent data and reduces code bloat, allowing developers to focus on application logic rather than data integrity management. In addition, Fauna offers native migration functionality to ensure the schema and the data in the database adhere to that new schema. A migration runs inside the database, is a background process, and completes while the database is serving production traffic with zero downtime. If an inbound transaction includes a document that has not been migrated yet, since Fauna is aware of the migration, it automatically migrates the document(s) to the new schema and then does the inbound transaction.

MongoDB’s querying is limiting and complex

MongoDB’s query language and Aggregation Framework are powerful but can become overly complex and verbose, but also limiting, especially for advanced queries. The framework requires chaining multiple stages ($match, $group, $project, etc.), which leads to long and difficult queries to work with. This verbosity makes writing and maintaining complex queries more time-consuming, with a steep learning curve for advanced operations.
While many developers turn to the Mongoose ORM to avoid MongoDB’s query tools, this approach introduces its challenges. Mongoose adds a layer of obfuscation that can lead to performance overhead and increased difficulty in debugging. Although it simplifies basic CRUD operations, developers still write raw MongoDB queries for more complex operations, undermining many of the benefits of using the ORM. Additionally, Mongoose does not solve MongoDB’s lack of global consistency, traversable relationships between documents, or strict serializability. It’s putting lipstick on a pig.
The Fauna Query Language (FQL) offers a more concise, expressive, and functional syntax. Unlike MongoDB’s multi-stage aggregation model or Mongoose, FQL allows queries to be written in a composable, declarative way, making it easier to construct and maintain. FQL’s approach leads to cleaner, more readable code, especially for complex operations. If you’ve coded JavaScript or TypeScript, you’ll pick up FQL very quickly.

MongoDB is not a fully managed or truly serverless database

While MongoDB Atlas is a managed service, it still requires manual configuration for scaling, backups, and infrastructure management. You must decide on instance sizes, regions, and clusters, which adds operational complexity. While MongoDB also has Atlas Serverless and automates some tasks, it is not a truly serverless solution because you still need to manage some of the underlying infrastructure, such as provisioning resources and handling scaling decisions. Further, MongoDB no longer supports native HTTPS connectivity, so for serverless or edge architectures, developers must implement additional management, configuration, and middleware to establish stateless communication with functions like Cloudflare Workers or AWS Lambda, increasing operational burden and potentially impacting performance.
Fauna is a fully managed, truly serverless database out of the box. Developers don’t need to worry about server management, scaling, backups, or provisioning. Fauna automatically scales based on demand and handles infrastructure management behind the scenes. This means no manual sharding, replication, or instance selection—everything is abstracted away. Fauna’s serverless nature allows it to scale effortlessly with zero operational overhead, making it ideal for dynamic workloads that require elastic scaling without intervention. In addition, unlike MongoDB, Fauna’s connectivity is a native HTTP-based API that is ideal for serverless apps, especially edge apps. You can use a lightweight language-specific client driver or plain HTTP to transact with Fauna without worrying about connection pooling.

Strict serializability out of the box

MongoDB provides eventual consistency by default and only offers stricter consistency guarantees at the cost of performance. To achieve full ACID transactions and strict consistency, developers must explicitly configure MongoDB, which can result in added complexity and slower write performance. Even then, MongoDB’s consistency can vary depending on how it’s set up, and global data distribution can introduce latency or consistency trade-offs.
Fauna, by contrast, provides strict serializability by default, meaning all transactions are executed in a globally consistent manner, ensuring that every read reflects the most recent write regardless of where that read originated geographically. This makes Fauna ideal for applications without worrying about complex configurations or performance trade-offs. Fauna’s unique consistency model provides global ACID transactions without sacrificing performance, making it simpler and more reliable for developers who need strong consistency across distributed data.

Conclusion

It’s clear that while MongoDB offers flexibility, it comes with trade-offs that require additional effort in code and operations. From schema validation inconsistencies to the complexities of its Aggregation Framework, MongoDB often requires extra tools and workarounds, like the Mongoose ORM, to attempt to maintain data integrity and performance. Fauna, on the other hand, provides a truly serverless experience with strict serializability, an intuitive query language, bonafide relationships between document data, and built-in global consistency, reducing the burden on developers. By eliminating the need for manual schema migrations, complex aggregations, and operational overhead, Fauna helps you build faster, more reliable applications with less effort.
If you’re looking for a database that scales with your needs while simplifying your workflow, Fauna is the choice for modern development. For a deeper dive into how Fauna out-performs Mongo, check out the 'Moving Beyond the Limits of MongoDB with Fauna' white paper. Explore the docs and sign up for a free account to get started building.

If you enjoyed our blog, and want to work on systems and challenges related to globally distributed systems, and serverless databases, Fauna is hiring

Share this post

‹︁ PreviousNext ›︁

Subscribe to Fauna's newsletter

Get latest blog posts, development tips & tricks, and latest learning material delivered right to your inbox.