# MongoDB vs PostgreSQL: source lines of code compared

The MongoDB vs PostgreSQL comparison on OctoCounts shows side-by-side source line counts for mongodb/mongo and postgres/postgres, counted with the same engine and analysis options on the dates shown in the methodology line: files, total lines, code lines, comment lines, blank lines, and per-language totals, pinned to the exact commits listed below.

As of 2026-09-16, mongodb/mongo contains 8,405,704 total lines (5,888,453 code) across 29,659 files, while postgres/postgres contains 3,205,371 total lines (1,817,922 code) across 5,354 files as of 2026-09-21. mongodb/mongo is about 3.2x the size of postgres/postgres by code lines. Code size is not code quality: a larger count only means more source material, not a better or worse project.

| Metric | [mongodb/mongo](https://octocounts.com/github/mongodb/mongo) | [postgres/postgres](https://octocounts.com/github/postgres/postgres) |
| --- | ---: | ---: |
| Files | 29,659 | 5,354 |
| Total lines | 8,405,704 | 3,205,371 |
| Code lines | 5,888,453 | 1,817,922 |
| Comment lines | 1,510,023 | 931,501 |
| Blank lines | 1,007,228 | 455,948 |
| Languages counted | 12 | 12 |

Top languages in mongodb/mongo: C++ (34.0% of code), C++ Header (21.4% of code), C Header (16.3% of code). Top languages in postgres/postgres: C (55.2% of code), PO File (22.5% of code), SQL (7.5% of code). C Header, C appear in both top language lists; C++, C++ Header, JavaScript appear only in mongodb/mongo's top languages; PO File, SQL, Perl appear only in postgres/postgres's top languages.

Methodology: both counts come from cached OctoCounts reports generated with tokei. mongodb/mongo was counted at ref 0a68308f0d39a928ed551f285ba72ca560c38576 (commit 0a68308f0d39) on 2026-09-16; postgres/postgres was counted at ref master (commit 9e17d25e79d4) on 2026-09-21. See the [counting methodology](https://octocounts.com/docs/methodology) for ignored directories and analysis options.
## About this comparison

mongodb/mongo counts the MongoDB server repository: the database core in C++, with storage engines and third-party libraries vendored in-tree. postgres/postgres counts the PostgreSQL source tree: the backend, planner, executor, and client interfaces, written in C. Both are complete database server source trees counted with the same engine on the dates shown above, making this a like-for-like category comparison.

The per-language tables reflect each project's implementation language directly: MongoDB's counted tree is C++-dominated with vendored components contributing further C and C++, while PostgreSQL's is overwhelmingly C — so the language mix here is a direct readout of each codebase's tradition.

MongoDB's count includes vendored storage-engine and dependency code alongside its own server code, while PostgreSQL's single tree has long contained the whole system — meaning the totals include different amounts of third-party material on each side.

_Server source size does not measure query performance, throughput, or operational cost for your workload; those depend on the built system, schema, and configuration, none of which appear in these counts._

Sources: [mongodb/mongo repository (C++ database server core)](https://github.com/mongodb/mongo) · [postgres/postgres repository (C database server source tree)](https://github.com/postgres/postgres). Statements verified 2026-09-16.

Evidence and next steps:

- [mongodb/mongo SLOC report](https://octocounts.com/github/mongodb/mongo)
- [postgres/postgres SLOC report](https://octocounts.com/github/postgres/postgres)
- [Compare mongodb/mongo and postgres/postgres interactively](https://octocounts.com/compare?left=https%3A%2F%2Fgithub.com%2Fmongodb%2Fmongo&right=https%3A%2F%2Fgithub.com%2Fpostgres%2Fpostgres)

Note: code size is not code quality. OctoCounts only reports reproducible line counts and makes no claim that either project is better.

## Compare FAQ

### Which has more lines of code, mongodb/mongo or postgres/postgres?

mongodb/mongo has more code: 5,888,453 code lines versus 1,817,922 for postgres/postgres, about 3.2x as much, based on cached OctoCounts reports as of 2026-09-21.

### Does more source lines of code mean more complexity?

Not necessarily. SLOC measures size, not complexity, quality, or maintainability. A larger codebase can mean more features, more generated or vendored code, more verbose language idioms, or more tests — none of which imply the code is harder to work with. Use SLOC to gauge the scale of what you'd be reading or maintaining, not as a quality signal for mongodb/mongo, postgres/postgres, or any repository.

### How is this comparison calculated?

Methodology: both counts come from cached OctoCounts reports generated with tokei. mongodb/mongo was counted at ref 0a68308f0d39a928ed551f285ba72ca560c38576 (commit 0a68308f0d39) on 2026-09-16; postgres/postgres was counted at ref master (commit 9e17d25e79d4) on 2026-09-21. See the counting methodology for ignored directories and analysis options.

### Can I compare a different branch, tag, or commit?

Yes. This page shows the default branch for each repository. Use the interactive comparison tool to pick any public GitHub repository, branch, tag, or commit SHA for both sides and get a fresh side-by-side report.

## Related OctoCounts pages

- [Interactive repository comparison](https://octocounts.com/compare)
- [Recently analyzed repositories](https://octocounts.com/recent)
- [Popular SLOC reports](https://octocounts.com/popular)
- [Trending GitHub repositories](https://octocounts.com/trending)
- [Hall of Monoliths](https://octocounts.com/hall-of-monoliths)
- [Original research: how filtering changes SLOC counts](https://octocounts.com/research)
- [GitHub SLOC counter guide](https://octocounts.com/docs/github-sloc-counter)
- [Counting methodology](https://octocounts.com/docs/methodology)
- [SLOC and code metrics glossary](https://octocounts.com/docs/glossary)
- [OctoCounts API docs](https://octocounts.com/docs/api)
