Fauna for MongoDB users
This guide outlines major differences between MongoDB and Fauna. The guide also translates common MongoDB Query Language (MQL) queries to Fauna Query Language (FQL) and Fauna Schema Language (FSL).
Major differences
The following table outlines major differences between MongoDB and Fauna.
Difference | MongoDB | Fauna |
---|---|---|
Data model |
Document database. Stores data as denormalized JSON-like documents in collections. |
Document-relational database. Stores data as denormalized and normalized JSON-like documents in collections with relationship traversals. |
Access control |
Role-based access control (RBAC). |
RBAC and attribute-based access control (ABAC). Roles and privileges can be assigned dynamically based on conditions at query time. |
Administration |
Uses managed clusters that require configuration and sizing for best performance and costs. |
Fully managed infrastructure that scales automatically. No configuration or sizing needed. |
Connection methods |
Client drivers. |
Client drivers and HTTP API. |
Consistency |
Strong consistency requires additional configuration and may impact performance. Distributed, consistent transactions across shards require specific configuration. |
Strong consistency by default across multiple regions, continents, and clouds. No configuration needed. No performance impacts. |
Distribution |
Single region by default. Multi-region are configurations available at additional costs. |
Natively multi-region. Multi-region setups require no additional costs or maintenance. Supports multi-cloud setups with Virtual Private Fauna. |
Indexes |
Supports single, compound, geospatial, and text search indexes. Managing indexes across multiple shards may require rolling index builds and changes to application logic. |
Supports single field and compound indexes. Indexes with terms are automatically sharded (partitioned) with no operational overhead. Sharding is transparent to the client applications. |
Multi-tenancy |
No native concept of multi-tenancy. Multi-tenancy is handled by the client application. |
Natively multi-tenant. Uses a nested database-per-tenant model that can scale to hundreds of thousands of tenants. Tenant databases are instantly allocated and logically isolated from peers. |
Schema |
Schemaless. Offers schema validation for document writes, but no native support for migrating existing documents. |
Supports a progressive schema enforcement, letting you migrate from schemaless to strict enforcement of document types. Zero-downtime migrations let you update existing documents to the latest schema. Supports constraints for custom data validation rules. |
Sharding |
Unsharded by default. Clusters can be configured as sharded, which results in reduced capabilities. |
Natively sharded with no configuration needed. Sharding is transparent to client applications. |
Streaming |
Offers change streams to track real-time data changes. You can subscribe to data changes on a single collection, a database, or deployment. |
Offers event streams to track real-time data changes. You can subscribe to changes for a collection, index, document, or specific fields. |
Examples
The following examples compare basic operations in MongoDB and Fauna. MongoDB examples use MQL. Fauna examples use FQL and FSL.
Create and manage collections
Create a schemaless collection
In a schemaless collection, documents can contain any field of any type. Documents in the same collection aren’t required to have the same fields.
Create a collection with predefined fields
Predefined fields let you control what fields are accepted in a collection’s documents.
Create and manage documents
Indexes and read queries
Document relationships
Create a relationship between documents
The following examples create:
-
A one-to-one relationship between a
Order
collection document and aCustomer
document. -
A one-to-many relationship between the
Order
document and severalOrderItem
documents. -
A one-to-one relationship between each
OrderItem
document and aProduct
document.
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!