Skip to content

Decisions7 min read

PostgreSQL or MongoDB for a business app: which one, and why

By Published

Short answerFor a business app where invoices, stock and payments must agree with each other, I choose PostgreSQL: the database itself enforces the rules, and reports come from ordinary SQL joins. MongoDB is a sound choice when each record stands alone and its shape varies, such as a catalogue or form submissions. Both can be self-hosted or rented as a managed service. PostgreSQL is the default in my packages.

One order with three lines, stored both ways

Take one order. Two chairs at $150, one desk at $400 and four lamps at $25. That is $300, $400 and $100, so the order total is $800.

In PostgreSQL this is usually three tables. One row in an orders table holds the customer, the date and the total. Three rows in an order lines table each hold a quantity and a price, and each points at its order and at a row in the products table. That pointer is a foreign key, which PostgreSQL's documentation defines as a rule that values in a column must match values appearing in some row of another table. A line for a product that does not exist is refused.

In MongoDB the same order is usually one document: the order's own fields, with a list of three line items inside it. MongoDB's documentation calls this embedding, and says it lets an application retrieve related data in a single database operation and update it in a single atomic write. The order arrives whole. Nothing has to be joined to print it.

Both are sensible. They differ once that order touches stock and a report.

Invoices and stock: who stops a wrong number being saved

This is the part an owner feels. An invoice whose lines do not match its total, or stock that says 4 when the shelf holds 3, costs someone an afternoon.

PostgreSQL lets me write the rules into the database. Its documentation lists check constraints (a price must be greater than zero), not-null constraints, unique constraints (one row per product number) and foreign keys, and says that if anyone tries to store data that would violate a constraint, an error is raised. The rule holds whichever screen, script or import sent the data.

Selling the order above means three things at once: save the order, save its lines, reduce stock for three products. PostgreSQL wraps them in a transaction, which its documentation describes as bundling multiple steps into a single, all-or-nothing operation. If the stock update fails, the order is not saved either. PostgreSQL's site says it has been ACID-compliant since 2001.

MongoDB works differently, and I want to state it fairly. An operation on a single document is atomic, so the order with its three embedded lines is saved whole or not at all. Stock lives in other documents. For that, MongoDB supports transactions across several documents, and its own documentation adds a caution: in most cases they cost more than single-document writes, and they should not replace effective schema design.

MongoDB also has schema validation, which by default rejects any insert or update that breaks your rules for field types and value ranges. The same page says documents in a collection do not need the same fields unless you add those rules, and that validation is most useful once the data structure is established. So the tools exist on both sides. In MongoDB they are opt-in.

Reports: SQL joins against an aggregation pipeline

Owners ask questions nobody planned for. Which products sold best per branch last quarter? Which customers have unpaid invoices older than 30 days?

In PostgreSQL those are join queries, which the documentation defines as queries that access multiple tables at one time. Because orders, lines, products and customers sit in separate tables, any combination can be asked later.

MongoDB answers reports with an aggregation pipeline: a series of stages, where each stage filters, groups or calculates and passes its output to the next. Combining collections uses a stage called $lookup, which MongoDB describes as a left outer join to a collection in the same database. Its documentation also suggests an embedded data model to reduce reliance on $lookup. That is the trade. MongoDB is at its best when a report reads documents the way they were stored. PostgreSQL is built for questions that cut across them.

When the data keeps changing shape: jsonb and documents

Flexibility is MongoDB's strongest argument. Its documentation says documents in one collection are not required to have the same fields, and that you can add new fields without rewriting existing documents or running a schema migration. That suits a catalogue whose items have very different attributes.

PostgreSQL has an answer inside the same database: a column type called jsonb, which stores a JSON document in a row. The documentation says most applications should prefer jsonb over the plain json type, and that it can be indexed to search for keys or key and value pairs across a large number of documents. I use it for the parts that vary, such as product attributes or a form's answers, and keep money, quantities and links in ordinary columns.

PostgreSQL's documentation adds two cautions I agree with. JSON documents should still have a somewhat fixed structure, because a predictable structure makes summary queries easier to write. And any update locks the whole row, so documents should stay a manageable size. MongoDB has a ceiling of its own: a document must be smaller than 16 mebibytes.

Licence and hosting: what you may do, and who runs the server

PostgreSQL is released under the PostgreSQL License, which its site describes as a liberal open source licence similar to the BSD or MIT licences. The same page says there are no plans to change it. You can run it on your own server, and postgresql.org keeps a list of hosting providers by region.

MongoDB Community Server uses the Server Side Public License (SSPL) for versions released on or after 16 October 2018. MongoDB's FAQ says the SSPL's main condition applies only when you offer MongoDB's functionality to third parties as a service, and that there is no copyleft condition for other SaaS applications that use MongoDB as a database. An ordinary business app is in that second group. The FAQ also states that the SSPL has not been approved by the Open Source Initiative. MongoDB's managed service is Atlas, which runs your database on AWS, Azure or Google Cloud and handles provisioning, patching, backup, monitoring and scaling.

This is not legal advice. If you plan to resell a hosted database to your own customers, have a lawyer read the licence first.

PostgreSQL and MongoDB on six points an owner notices

My decision rule: if two records have to agree with each other for the business to be right, such as invoice and payment, stock and sale, or seat and ticket, choose PostgreSQL. If each record stands on its own, is read and written whole, and varies in shape from one to the next, MongoDB is a reasonable choice.

What you care aboutPostgreSQLMongoDB
Numbers that must agreeConstraints and foreign keys refuse bad data; transactions are all or nothingSingle-document writes are atomic; multi-document transactions exist, with a cost MongoDB's docs warn about
Rules on what can be savedDeclared with the tablesOptional schema validation, added per collection
Reports across recordsSQL joins across any tablesAggregation pipeline, with $lookup to join collections
Data that varies per recordjsonb columns beside ordinary columnsThe native model: documents need not share fields
LicencePostgreSQL License, similar to BSD or MITSSPL for Community Server; supported drivers under Apache 2.0
Managed hostingMany providers, listed by region on postgresql.orgAtlas on AWS, Azure and Google Cloud

PostgreSQL is my default, and the cases where I would use MongoDB

My Growth package ($1,699, up to 25 screens) and Scale package ($2,500, up to 50 screens) both come with a Node.js backend and a PostgreSQL database. That default is deliberate. Ordering, memberships, bookings and delivery all involve records that must agree. Launch ($999, up to 10 screens) connects to the APIs you need, so the question rarely comes up there.

I would still pick MongoDB when the core of the product is documents with varied shapes, such as a content library, a catalogue with very different attributes per item, or raw event logs, and there is little money or stock logic around them.

If your developer has proposed MongoDB, ask one question: which rules will the database enforce, and which will only the application code enforce? A clear answer is a good sign, whichever database it is.

ERP, POS, CRM and SaaS builds are custom software, quoted as a fixed price after a written scope. Hosting, third-party fees and ongoing maintenance are not included.

Questions

Can I use MongoDB in a commercial app without open-sourcing my code?
MongoDB's SSPL FAQ says there is no copyleft condition for SaaS applications that use MongoDB as a database. The condition applies when you offer MongoDB's own functionality to third parties as a service. This is not legal advice; confirm your case with a lawyer.
Can PostgreSQL store flexible JSON data the way MongoDB does?
Yes, in jsonb columns, which can be indexed and queried. PostgreSQL's documentation still recommends a somewhat fixed structure and documents of a manageable size. I use jsonb for the parts that vary and ordinary columns for money and quantities.
Can we switch from one database to the other later?
Yes, but it is a migration project. Documents have to be split into tables, or tables folded into documents, and every query and report is rewritten. I would settle the choice before the build starts.

Sources

Platform rules and fees in this article were checked against these official pages on 12 November 2026. They change, so confirm before you rely on them.

Sannan Malik is a software architect and product builder with 8+ years in software, CEO of Alpha Notic FZE and a Certified Scrum Product Owner. He builds mobile apps and business software for companies in the UAE, the wider Gulf, the UK, the US, Canada and Australia.

Let's build it

Got an idea? Let's talk.

The fastest way to reach me is WhatsApp. Tell me what you're building and I'll reply with how I'd approach it, which package fits, or what a custom scope would look like.

Message me on WhatsApp