MongoDB vs PostgreSQL: PostgreSQL by Default, MongoDB for Self-Contained Documents

Pick PostgreSQL by default, and pick MongoDB when each record is a self-contained document whose shape varies or when you expect to shard writes soon. The limits and version details below come from the vendors’ own pages, the PostgreSQL documentation resources page and the MongoDB documentation. The performance claims in circulation need more care than the verdict does: one published test on current versions is Waseem Anjum’s JSONB benchmark of MongoDB 9.0 against PostgreSQL 18, published 29 October 2026 (checked 15 November 2026).

Google ยท Preferred Sources

Don't miss new tech stories on Google

Add Tech Insider once in the Google app and our stories appear in your news suggestions.

Add Now

Which database for which situation

SituationPickReason
Related entities, transactions and reporting in one productPostgreSQLJoins and SQL reporting run in the database that holds the transactions
Mostly relational data with a few flexible fieldsPostgreSQLA JSONB column holds the flexible part
Self-contained documents with frequently changing shapeMongoDBOne document is read and written as a unit
Write sharding expected soonMongoDBSharding is built in
AttributeMongoDBPostgreSQL
Data modelJSON-like documents in collectionsRows in tables with declared columns, plus the jsonb type
LicenceServer Side Public License (Community Server)PostgreSQL Licence (permissive)
Scale-outSharding built inSingle primary with replicas and partitioning
Size limit16 MB per BSON document1 GB per field value
Current version9.018 (18.7 released 12 November 2026)

Which benchmarks transfer to current versions

Check the versions and the indexing in every comparison before you quote it. We ran no benchmarks of our own; the table matches the published current-version result to the versions and setup it covers.

SourceVersionsSetup coveredLimit
Waseem Anjum, published 29 October 2026 (checked 15 November 2026)MongoDB 9.0, PostgreSQL 18JSONB inserts, lookups, updates and storage; the per-operation figures are in the postA JSONB comparison, so it does not settle workloads outside JSONB

Treat the result as one data point on JSONB, and check your own data shape before reading it as a ranking.

Limits and scale that decide it

A MongoDB BSON document is capped at 16 MB, per the MongoDB documentation, so records that can grow past that need references instead of embedding. PostgreSQL’s maximum field value is 1 GB, per its documentation’s limits appendix. Choose MongoDB for sharding only when single-node write capacity is short after partitioning and vertical scaling. Measure peak writes per second, working-set size against RAM, and yearly growth first.

On licensing, MongoDB’s licensing page lists Community Server under the Server Side Public License. Have legal review confirm the SSPL terms against your use, particularly if you plan to offer the database as a service. For hosting, compare Atlas against managed PostgreSQL at equal RAM and equal failover topology, using each vendor’s current price page. On versions, the PostgreSQL site lists 18 as current (18.7 released 12 November 2026) with 19 in release-candidate stage, and MongoDB documents 9.0 as its current release.

Moving from MongoDB to PostgreSQL with a script that fails safely

Decide first which fields become columns and which stay in a JSONB column, and turn embedded arrays into child tables. The script below reads credentials, batch size and sample size from environment variables, inserts in batches, rolls back on any error and compares counts at the end. The users table needs id as a primary key.

import os

import psycopg2
from bson import json_util
from psycopg2.extras import Json, execute_values
from pymongo import MongoClient

BATCH = int(os.environ["BATCH"])  # rows per insert batch
SAMPLE = int(os.environ["SAMPLE"])  # sample run; raise for the full load
KNOWN = ("_id", "email", "name", "created_at")

def dumps(obj):
    return json_util.dumps(obj)  # ObjectId, Decimal128 and dates become extended JSON

mongo_client = MongoClient(os.environ["MONGO_URI"])
pg_conn = psycopg2.connect(os.environ["PG_DSN"])
try:
    mongo_db = mongo_client["production"]
    coll = mongo_db["users"]
    expected = min(coll.count_documents({}), SAMPLE)
    pg_cursor = pg_conn.cursor()
    batch = []
    for doc in coll.find().limit(SAMPLE):
        extra = {k: v for k, v in doc.items() if k not in KNOWN}
        batch.append((str(doc["_id"]), doc.get("email"), doc.get("name"),
                      Json(extra, dumps=dumps), doc.get("created_at")))
        if len(batch) >= BATCH:
            execute_values(pg_cursor, "INSERT INTO users (id, email, name, metadata, created_at) "
                                      "VALUES %s ON CONFLICT (id) DO NOTHING", batch)
            batch.clear()
    if batch:
        execute_values(pg_cursor, "INSERT INTO users (id, email, name, metadata, created_at) "
                                  "VALUES %s ON CONFLICT (id) DO NOTHING", batch)
    pg_cursor.execute("SELECT count(*) FROM users")
    (loaded,) = pg_cursor.fetchone()
    if loaded != expected:
        raise RuntimeError(f"count mismatch: mongo {expected}, postgres {loaded}")
    pg_conn.commit()
except Exception:
    pg_conn.rollback()
    raise
finally:
    pg_conn.close()
    mongo_client.close()

Going the other way, embed rows that are always read together and keep references where a document would approach the 16 MB cap. Run the script on a small sample first (set SAMPLE), then compare row counts and query plans against your real queries. The PostgreSQL announcement of 12 November 2026 lists PostgreSQL 19 release candidate 2 and gives a planned general-availability date of 19 November 2026 (checked 15 November 2026), so confirm the target major version before the full load.

Marcus Chen

Marcus Chen

PC hardware, storage and engineering

Marcus Chen covers PC hardware, storage and engineering for Tech Insider: processors, graphics cards, SSDs and hard drives, home servers and backup, and the engineering choices behind them. He builds comparisons from manufacturers' specifications, published independent test results and Tech Insider's own calculations, and writes plainly about what the evidence supports.

View all articles