Databases 11 min read

Postgres vs MongoDB: Which Database Wins in 2023?

This article provides a comprehensive comparison between PostgreSQL and MongoDB across dimensions such as license, data model, JSON support, performance, reliability, scalability, usability, operability, and ecosystem, helping readers decide which database better fits their application requirements in 2023.

ITPUB
ITPUB
ITPUB
Postgres vs MongoDB: Which Database Wins in 2023?

This is the second article in the "Full‑Scope Database Comparison" series, following the earlier Postgres vs MySQL comparison.

Why Compare Postgres and MongoDB

According to the 2023 Stack Overflow survey, PostgreSQL is the most popular and most wanted database. MongoDB held the top spot for four consecutive years (2017‑2020) in the DB‑Engines ranking, and both sit in the top‑5, competing for market share against Oracle, MySQL and Microsoft SQL Server.

MongoDB is traditionally seen as a NoSQL alternative to relational databases like Postgres, but the two are converging:

MongoDB now offers multi‑document ACID transactions, secondary indexes and advanced query capabilities, making it behave more like a relational system.

Postgres continues to improve its JSON handling—adding indexes, query optimisations and new operators—raising the question of whether MongoDB is becoming obsolete.

License

Postgres is released under the PostgreSQL licence, a permissive BSD‑style open‑source licence.

MongoDB Community Edition uses the Server Side Public License (SSPL), which restricts providing MongoDB as a service without a commercial licence; a commercial licence is also available.

Both licences permit internal use by companies.

Data Model

Postgres is a relational database that stores data in predefined columns and uses foreign keys to relate tables.

MongoDB is a document‑oriented database; data is stored as JSON‑like documents in collections, supporting nested fields and arrays, making it suitable for semi‑structured data.

Postgres also supports JSON columns, allowing a document‑style table definition such as:

CREATE TABLE my_collection (
   id SERIAL PRIMARY KEY,
   data JSONB
);

JSON Support

Both databases handle JSON efficiently. MongoDB stores JSON in BSON format, while Postgres uses JSONB. For a deeper discussion, see https://bit.ly/3pRLOzi.

MongoDB advantages:

Built‑in schema validator.

Seamless integration with the Node.js ecosystem, making it a favourite for full‑stack developers.

Performance

Performance depends on access patterns. MongoDB often excels with denormalised data and simple queries because it avoids costly joins. Postgres shines with complex queries thanks to SQL and its advanced optimiser.

Reliability

MongoDB’s early lack of ACID transactions made it seem less reliable, but after adopting the WiredTiger storage engine, its transaction reliability matches Postgres.

MongoDB provides automatic failover via replica sets; Postgres typically relies on third‑party tools like pg_auto_failover.

Scalability

MongoDB scales out horizontally (sharding) out of the box. Postgres traditionally scales up vertically, though sharding is possible (see Instagram sharding article and Notion’s Postgres sharding experience).

Usability

MongoDB’s schema‑less design and early Node.js driver make it easy to start with, especially for full‑stack developers.

Postgres enforces schemas more strictly than many other relational databases, including MySQL.

Stack Overflow data shows Postgres is the most loved database, while MongoDB is more popular among beginners.

Operability

Running a multi‑node MongoDB cluster is simpler because sharding and failover are built‑in. Running a multi‑node Postgres cluster often requires additional tooling.

Many providers offer managed Postgres services; MongoDB’s licence limits third‑party hosted services, but MongoDB Atlas provides a comprehensive managed offering.

Ecosystem

Postgres has a vibrant, community‑driven ecosystem with numerous extensions and is supported by many hosted providers (Heroku, Supabase, Render, Fly.io).

MongoDB, as a commercial open‑source company, expands its ecosystem through acquisitions (WiredTiger, mLab, Realm, Compass) and a strong focus on developer tooling.

Postgres or MongoDB?

Choose Postgres for applications with complex business logic and demanding queries.

Choose MongoDB for simple data models that need to handle massive volumes.

In many cases both are viable: MongoDB offers first‑class JSON support, while Postgres provides the best JSON capabilities among open‑source relational databases.

Full‑stack developers may prefer MongoDB for its Node.js integration, but the growing availability of managed Postgres services narrows the gap.

Overall, Postgres is a versatile, relational, SQL‑rich database with a strong community, while MongoDB delivers a comprehensive document‑model solution with built‑in scalability and a commercial backing.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

ScalabilityJSONPostgreSQLLicenseMongoDBdatabase comparisonOperability
ITPUB
Written by

ITPUB

Official ITPUB account sharing technical insights, community news, and exciting events.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.