When someone needs to store JSON documents, the first option that usually comes to mind is MongoDB.
But today, PostgreSQL, using JSONB, solves this problem so efficiently that in many projects, it doesn't make sense to add another database just for that.
What is JSONB?
JSONB is a PostgreSQL data type that stores JSON documents in binary format.
In practice, this means:
fast queries on internal fields; indexing of JSON attributes; full ACID transaction support; ability to mix relational data and documents in the same table.Example:
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name TEXT,
profile JSONB
);
{
"theme": "dark",
"notifications": true,
"networks": {
"github": "thiagolucio",
"linkedin": "thiagolucio"
}
}
You can query any field:
SELECT *
FROM users
WHERE profile->>'theme' = 'dark';
Or even index this attribute to make it extremely fast.
Why can this be better than MongoDB?
1. One database for everythingInstead of maintaining PostgreSQL for relational data and MongoDB for documents, you use only PostgreSQL.
Less infrastructure, less backup, less monitoring, and less complexity.
2. Real ACID
PostgreSQL has always had one of the most robust transaction models on the market.
When multiple operations need to happen together, you have strong consistency guarantees.
3. JOINs still exist
If tomorrow part of your JSON becomes a normal table, you just do a JOIN.
You don't need to migrate technology.
4. Efficient indexes
PostgreSQL has GIN indexes for JSONB, allowing very fast queries on large documents.
You can search by keys, values, and internal structures without having to traverse the entire document.
5. SQL is still SQL
You can combine relational queries with JSON in the same statement.
Example:
SELECT name
FROM users
WHERE profile->>'theme' = 'dark'
AND created_at >= CURRENT_DATE - INTERVAL '30 days';
This flexibility is hard to find in databases that are strictly document-oriented.
So, has MongoDB become bad?
No.
MongoDB remains an excellent choice for specific scenarios, especially when virtually all data consists of highly flexible documents and the application was designed around that model.
But for many web applications, APIs, and enterprise systems, PostgreSQL delivers the best of both worlds: relational data and JSON documents in the same database.
The result is usually a simpler architecture, fewer services to maintain, and a shorter learning curve for those who already work with SQL.
In the end, the best technology depends on the problem. Just remember that in 2026, choosing MongoDB just because you "need to store JSON" is no longer as obvious a decision as it was a few years ago.