Compare

Dgraph vs MongoDB

Which is the Best Graph Database?

Updated in July 2021

Dgraph MongoDB
Native GraphQL Support

Yes

Only DB to natively support GraphQL resulting in capacity to process GraphQL queries in parallel with high performance

No

MongoDB does not natively support GraphQL as a query language for accessing data stored within the database

Database Type

Distributed Graph database with the ability to use the same query everywhere as if querying a single database

MongoDb is a document-based NoSQL database. Unlike a graph database, connectivity within the data is not strongly supported.

Distributed ACID Transactions
  • Supported and Jepsen-tested
  • Synchronous replication with immediate consistency meaning any client can read the latest writ
  • Open source

Reference

MongoDB does not support ACID transactions. Instead, MongoDB exchanges ACID transactions for eventual consistency. This is a much weaker safety guarantee than an ACID-compliant database.

Distributed transactions are supported. However, multi-document transactions incurs a greater cost when compared to single document transactions. In effect, Mongo expects that transaction scope needs to be limited to a single document for highest performance.

Sharding
  • Predicate-based sharding. Avoids N+1 problem and network broadcasts when running a query in high fanout scenarios. This ensures low-latency query execution, irrespective of the size of the cluster or the number of intermediate results. Reference
  • Consistent production level latencies and consistent queries. Reference
  • Automatic sharding
  • Sharding a single predicate on the roadmap
  • Providing a sharding key is mandatory
  • Use of sharding key implies overheads on data modelling, indexing, and querying
Consistent Replication
Synchronous replication across all replicas

MongoDB always replicates data asynchronously from primary to secondaries

Adding replication puts additional constraints on the client. Here are a couple:
Asynchronous replication to secondaries means that reads from secondaries may return data that does not reflect the state of the data on the primary.

Multi-document transactions that contain read operations must use read preference primary. All operations in a given transaction must route to the same member.

Linearizable Reads
Strong (sequential) consistency across clients. Reference

Clients using a “local” read concern can see transaction data that might eventually get rolled back.

Correctness and Durability Testing
High Availability

Yes

  • HA Cluster Setup is explained here
  • HA Cluster setup is available in Community Edition
  • MongoDB allows for high availability through Replica-Sets.
  • The replication process depends on a special collection called “opLog”. This “opLog” needs to be configured based on users needs.
  • When the primary goes down or becomes unavailable, the secondaries will determine a new primary to make available
Transparent Data Encryption

Yes

Yes, database files are encrypted at rest with a user-specified key

MongoDB supports TLS/SSL to encrypt all of MongoDB's network traffic. 

Encryption at rest is also supported as an enterprise feature.

Query Languages

MongoDB Query Language (MQL)

Management of Runaway Queries
  • Context cancellation which works across clients and servers. So, a context cancellation at the client level would automatically cancel the query at all involved servers
  • OpenCensus integration, which allows distributed tracing all the way from app to Dgraph cluster and back
  • Open standards for query context cancellation and tracking

Runaway queries can be analyzed and killed by methods that are exposed in MongoDB. reference

Backups
  • Binary format
  • Both full and incremental backups to files, S3 and Google storage via Minio
  • Live backups with no downtime

Reference

  • Supported
Pricing and Free Trial
  • Open source version is under Apache 2.0, so free to use and modify
  • Enterprise version pricing is based on the number of instances of Dgraph, not the number of cores / RAM / Disk, etc…
  • Open source version is under SSPL v1.0 and free to use
  • Enterprise version pricing available for Cloud and On-premise
Appropriate as primary database to build apps/data platform on
Dgraph is a general-purpose database

MongoDB does not support data models designed via GraphQL schemas, and needs specialized data modelling knowledge around MongoDB collections, which slows down application development.

MongoDB is document-centric, and does not work well with use cases that revolve around knowledge graphs.

Open Source

Yes

  • Apache 2.0. GitHub
  • Enterprise features are NOT Apache 2.0. But, users can still read the source
  • Dgraph open source version and enterprise version provide the same performance. They’re only different in that enterprise version has more features
  • Dgraph supports many open standards, like Grpc, Protocol Buffers, Go contexts, Open Census integration for distributed tracing
Open Source under the Server Side Public License (SSPL) v1.0 licence
Protocols
  • HTTP/HTTPS
  • gRPC
  • Protocol Buffers

The MongoDB Wire Protocol is a simple socket-based, request-response style protocol. Clients communicate with the database server through a regular TCP/IP socket.

reference

Point in Time Recovery

On the roadmap

Supported via Mongo Ops Manager

reference

Multi-Region Deployments

Yes

Yes

SQL Migration Tool

Yes

No

There are 3rd party tools available though that can assist with varying degrees of accuracy

Authentication and Authorization
  • JSON web tokens
  • ACLs for enterprise
  • Integration with LDAP on the roadmap

Multiple authentication and authorization mechanisms supported. Certain mechanisms are only supported in MongoDB Enterprise including LDAP and Kerberos.

reference

Drivers
  • Dgraph’s drivers use gRPC not REST
  • Any GraphQL compatible client can be used
  • Dgraph’s supported drivers are the same as Neo4J’s supported drivers: Java, JavaScript , Go, Python, .Net
  • Dgraph’s unofficial drivers are: Rust, Dart, Elixir
Reference
Drivers supported for multiple programming languages like Java, Python, C#, and more. reference
Multi-Database Features

Multi-tenancy supported since Dgraph v21.03

Not supported natively

Graph Database as a Service (DBaaS)

No

Query Execution Plans
Query planning on the roadmap

the MongoDB query optimizer chooses and caches the most efficient query plan given the available indexes

Support for Graph Algorithms
  • Shortest k-paths
  • Edge traversal limit to determine cycles in graphs
  • Others requested from community listed here

No

Apache Spark Integration

Community plugin available

Supported

Kafka Integration

On roadmap

Supported

Import/ Export
  • Using BulkLoader or LiveLoader, Dgraph can read the data as is with no modification needed
  • Supported data formats are JSON and RDF
  • Exporting database is explained here
  • Supported

Get Started Today!

Dgraph gives you the scalability and performance you need with the pricing and transparency you expect. Start building today with the world’s most advanced and performant GraphQL platform.