// OSSeva Blog
MigrationMongoDB vs PostgreSQL: JSONB, Performance, Licensing and Which Is Better
The short answer
Choose MongoDB when your data is naturally a set of self-contained documents and you want sharding and failover built into the database. Choose PostgreSQL when your data has relationships you query across, or when you want JSON documents and relational tables in one engine. PostgreSQL's jsonb type stores JSON in a binary format with GIN indexing, so "we need JSON" alone is no longer a reason to pick MongoDB. MongoDB's case rests on its document model, drivers, replica sets and native sharding. Licensing differs too: MongoDB Community Server is under the SSPL, which the OSI does not approve, while PostgreSQL uses a permissive OSI-approved licence.
MongoDB vs PostgreSQL at a glance
| MongoDB | PostgreSQL | |
|---|---|---|
| Data model | Collections of BSON documents, flexible schema by default | Tables with a defined schema, plus json and jsonb columns |
| Licence | Community Server under the SSPL since 16 October 2018 (earlier versions AGPL v3.0) | PostgreSQL License, permissive |
| Transactions | Single-document operations are atomic; multi-document transactions on replica sets and sharded clusters | ACID transactions across any rows and tables |
| Joins | $lookup in aggregation; models usually embed related data | Full SQL joins |
| Scaling out | Native sharding with mongos routers and config servers | One writable primary; sharding through extensions such as Citus |
| High availability | Replica sets with automatic elections | Streaming replication; failover through tools such as Patroni |
| Document limit | 16 MiB per document; GridFS for larger files | Large jsonb values are stored out of line |
Licensing: SSPL vs the PostgreSQL License
MongoDB moved Community Server to the Server Side Public License on 16 October 2018. Every version and patch release from that date is under the SSPL, including later patches to older lines; earlier releases stay under AGPL v3.0. MongoDB's own FAQ states that the SSPL is not OSI approved.
The obligation that matters is Section 13. If you offer MongoDB's functionality to third parties as a service, you must release the source of the whole service stack, including management, monitoring, backup and hosting software. MongoDB's FAQ is clear that this "applies only when you are offering the functionality of MongoDB" as a service, and that there is "no copyleft condition for other SaaS applications that use MongoDB as a database". For most companies that run MongoDB behind their own applications, the SSPL imposes nothing extra. It does matter for platform teams offering databases as an internal or external service, and for organisations whose open source policy accepts only OSI-approved licences.
PostgreSQL's licence is short, permissive and OSI-approved, with no service clause. That is one reason cloud providers, appliance makers and SaaS platforms build on it freely.
MongoDB vs PostgreSQL JSONB
PostgreSQL has two JSON types. json keeps the exact input text; jsonb stores a decomposed binary form that is slightly slower to write and much faster to query, drops whitespace and duplicate keys, and does not keep key order. The PostgreSQL manual recommends jsonb for most applications.
A GIN index on a jsonb column supports containment (@>), key-exists operators and SQL/JSON path queries, so you can index whole documents without naming fields in advance. The jsonb_path_ops operator class gives a smaller, more selective index if you do not need key-exists tests. You can also index a single expression, such as (doc->>'customer_id'), with a B-tree.
| Task | MongoDB | PostgreSQL jsonb |
|---|---|---|
| Find by a field value | db.orders.find({ status: "paid" }) | SELECT * FROM orders WHERE doc @> '{"status": "paid"}' |
| Read a nested field | Projection { "customer.name": 1 } | doc->'customer'->>'name' |
| Index documents | Index on each queried field path | CREATE INDEX ON orders USING GIN (doc jsonb_path_ops) |
| Enforce structure | JSON Schema validation rules on the collection | Regular columns and constraints alongside the jsonb column |
| Join to other data | $lookup, or embed | SQL JOIN on any column or extracted value |
Where jsonb is weaker: a jsonb document is a single column value, so changing one key writes a new copy of the whole value in a new row version, and the old version waits for vacuum. Frequent small edits to large documents are therefore relatively expensive. The query language is also SQL with JSON operators rather than a document-native API. Where it is stronger: the same transaction can update a document and the relational rows around it, and reporting tools that speak SQL work on it directly.
MongoDB vs PostgreSQL performance
Benchmarks between the two are easy to find and hard to trust, because each side can pick a workload that suits its design. What the documentation of each supports:
- Reads of whole aggregates. A MongoDB document that embeds everything a page needs is read in one operation with no join. MongoDB's own guidance is to model data so that most operations touch one document; it warns that multi-document transactions carry "a greater performance cost over single document writes".
- Queries across entities. PostgreSQL's planner, joins, parallel query and index types suit queries that cut across many entities, ad hoc reporting and aggregations over normalised data.
- Write scaling. MongoDB shards a collection across replica sets natively. PostgreSQL scales writes on one primary and goes further with sharding extensions such as Citus, which is licensed AGPL-3.0.
Model a slice of your real workload in both and measure it, including the operational cost of running each at your scale.
Operations
MongoDB replica sets elect a new primary automatically, and drivers retry certain writes after a failover. Sharded clusters add mongos routers and a config server replica set. PostgreSQL needs an external failover manager such as Patroni or repmgr, and most teams already know its backup and recovery tools. On self-managed MongoDB, upgrades go one major version at a time with featureCompatibilityVersion raised at each step, and versions from 5.0 on x86_64 need CPUs with AVX; our posts on the MongoDB 4.4 to 7.0 upgrade and the MongoDB AVX requirement cover both.
MongoDB-compatible options on PostgreSQL
Two open source projects sit between the choices. DocumentDB, MIT-licensed, describes itself as "a MongoDB compatible open source document database built on PostgreSQL". FerretDB, Apache-2.0, is a proxy that turns MongoDB 5.0+ wire protocol requests into SQL against PostgreSQL with the DocumentDB extension. Both are worth testing if you want MongoDB drivers with a PostgreSQL back end; check feature coverage against the commands your application uses before relying on either.
Which is better, MongoDB or PostgreSQL?
- Choose MongoDB when the data is document-shaped and read as whole aggregates, the schema changes often, you need native sharding across many nodes, or your team and tooling are already built around MongoDB drivers. MongoDB Atlas is a reasonable option if you want MongoDB fully managed.
- Choose PostgreSQL when relationships and cross-entity queries matter, you want documents and relational data under one transaction, you prefer an OSI-approved permissive licence, or you are consolidating databases onto one engine.
- Keep what you have when the existing system works. Moving between a document model and a relational one is a redesign of the data layer, not a dump and load.
For vector search inside PostgreSQL, see pgvector in production. For the relational comparison, see PostgreSQL vs MySQL.
Where OSSeva fits
OSSeva supports both. OSSeva for MongoDB patches self-managed MongoDB Community Server 4.2, 4.4, 5.0 and 6.0 after end of life, including 4.4 builds for hardware without AVX, and OSSeva Assure adds a featureCompatibilityVersion upgrade plan and a driver compatibility audit. OSSeva does not support MongoDB Atlas, which MongoDB patches itself. OSSeva for PostgreSQL patches 11, 12 and 13, and 14 after 12 November 2026. Support starts on the binaries you already run, with no migration first; see MongoDB extended support. MongoDB is priced per replica set or cluster and sits under one contract with PostgreSQL, MySQL, Redis and Kafka. Book a discovery call for a quote. If you are comparing providers, our MongoDB support providers post covers the field.
Frequently asked questions
MongoDB vs PostgreSQL JSONB: which is better for JSON?
For JSON that lives beside relational data, or that you query with SQL, PostgreSQL jsonb with a GIN index is usually enough. For applications built entirely around documents, read and written as whole aggregates, and spread across shards, MongoDB fits better.
MongoDB vs PostgreSQL performance: which is faster?
It depends on the access pattern. Reading whole documents by key suits MongoDB's model; joins and queries across entities suit PostgreSQL. Test your real workload on both rather than relying on published benchmarks.
MongoDB vs PostgreSQL: which is better?
Neither in general. Pick MongoDB for document-shaped data with native sharding, and PostgreSQL for relational data, mixed workloads and a permissive licence.
Is MongoDB open source?
MongoDB Community Server is source-available under the SSPL, which the OSI has not approved; MongoDB itself says the SSPL is not OSI approved. Versions released before 16 October 2018 remain under AGPL v3.0.
Do I have SSPL obligations if my application uses MongoDB?
According to MongoDB's FAQ, no, unless you offer MongoDB's own functionality to third parties as a service. Using MongoDB as the database behind your application carries no copyleft condition.
Can PostgreSQL work with MongoDB drivers?
Through compatibility layers. FerretDB translates the MongoDB wire protocol to SQL on PostgreSQL with the DocumentDB extension. Test coverage of the commands you use before migrating.
Tags
Related articles
How to Consolidate Open Source Database Support Contracts Without Migrating Anything
October 7, 2026OperationsWho Supports PostgreSQL, MySQL, MariaDB, Valkey and RabbitMQ Under One Contract?
October 7, 2026MigrationMySQL 8.0 to 8.4 Upgrade Guide: Breaking Changes and How to Check for Each
October 7, 2026Ready to get your open source under control?
Talk to an OSSeva engineer about CVE coverage, compliance, and migration support for your stack.