百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
P

Pongo

> 数据库
开源

Pongo - Mongo,但使用 Postgres,具有强大的一致性优势

1.4K stars0 点赞0 次浏览
访问官网GitHub

工具介绍

Pongo - Mongo,但使用 Postgres,具有强大的一致性优势

Pongo

Pongo - Mongo but on PostgreSQL and with strong consistency benefits.

Getting Started

Install Pongo as an npm module and save it to your package.json:

bash
npm install @event-driven-io/pongo pg @types/pg

Read also introduction article on my blog for more context.

Example

You can use Pongo syntax with explicit typing about supported syntax:

…

Or use MongoDB compliant shim:

…

How does it work?

Pongo treats PostgreSQL as a Document Database benefiting from JSONB support. Unlike the plain text storage of the traditional JSON type, JSONB stores JSON data in a binary format. This simple change brings significant advantages in terms of performance and storage efficiency.

Pongo uses the following table structure for storing collections:

sql
CREATE TABLE IF NOT EXISTS "YourCollectionName" (
    _id           TEXT           PRIMARY KEY,
    data          JSONB          NOT NULL,
    metadata      JSONB          NOT NULL     DEFAULT '{}',
    _version      BIGINT         NOT NULL     DEFAULT 1,
    _partition    TEXT           NOT NULL     DEFAULT 'png_global',
    _archived     BOOLEAN        NOT NULL     DEFAULT FALSE,
    _created      TIMESTAMPTZ    NOT NULL     DEFAULT now(),
    _updated      TIMESTAMPTZ    NOT NULL     DEFAULT now()
)

Essentially Pongo takes MongoDB api and translates it to the native PostgreSQL queries. It is a similar concept to Marten, FerretDB and AWS DocumentDB.

E.g. the MongoDB update syntax:

typescript
const users = pongoDb.collection<User>("users");

await users.updateOne({ _id: someId }, { $push: { tags: "character" } });

will be translated to:

sql
UPDATE "users"
SET data = jsonb_set(data, '{tags}', (COALESCE(data->'tags', '[]'::jsonb) || to_jsonb('character')))
WHERE _id = '137ef052-e41c-428b-b606-1c8070a47eda';

Or for query:

typescript
const result = await users
  .find({ "address.history": { $elemMatch: { street: "Elm St" } } })
  .toArray();

will result in:

sql
SELECT data
FROM "users"
WHERE jsonb_path_exists(
  data,
  '$.address.history[*] ? (@.street == "Elm St")'
);

Why Pongo?

MongoDB is a decent database, yet it has issues around ACID-complaince and licensing, which can cause hardship for project scenarios and organisation policies.

Pongo brings the PostgreSQL shape-shifting capabilities to:

  • benefit from strong consistency by using battle-tested and widely used PostgreSQL ACID-compliant database,
  • easier integration with other parts of your system using PostgreSQL,
  • reuse your muscle memory from MongoDB using compatible API. It will allow easier migration of existing projects,
  • cut boilerplate and easier nested data management than traditional relational tables,
  • operate easier than crafting native PostgreSQL JSON queries. They're powerful but not the most accessible,
  • get performance boost with JSONB indexing capabilities,
  • benefit from PostgreSQL advanced capabilities like partitioning, logical replication and other PostgreSQL superpowers
  • seamless integration with Cloud RDSes and solutions like Supabase, Vercel Postgres, YugabyteDB, CockroachDB, .

Watch also more in:

Storage

The binary format of PostgreSQL JSONB means that data is pre-parsed, allowing faster read and write operations than text-based JSON. You don't have to re-parse the data every time you query it, which saves processing time and improves overall performance. Additionally, JSONB supports advanced indexing options like GIN and GiST indexes, making searches within JSONB documents much quicker and more efficient.

Moreover, JSONB retains the flexibility of storing semi-structured data while allowing you to use PostgreSQL's robust querying capabilities. You can perform complex queries, joins, and transactions with JSONB data, just as you can with regular relational data.

Contrary to common belief, JSON document data is structured. JSON has structure, but it is not enforced for each document. We can easily extend the schema for our documents, even for specific ones, by adding new fields. We should also not fail if a field we expect to exist doesn't.

This flexibility, performance, and consistency combination makes PostgreSQL with JSONB a powerful tool. There are benchmarks showing that it can be even faster than MongoDB.

Check more in:

  • JSON Types Documentation
  • JSON Functions and Operators
  • PostgreSQL, JSONB and GIN Indexes by
  • MongoDB vs PostgreSQL JSONB Benchmark
  • How to JSON in PostgreSQL
  • Just Use Postgres for Everything

Is Pongo an ORM?

It's not.

It's focused on effective handling of the document data specifics. Node.js ORMs have capabilities to handle JSONB, e.g. DrizzleORM has good support for that for basic operations.

Yet, they all have limited querying capabilities. Usually for advanced ones you need to fallback to JSONPath or JSONB functions (so raw SQL). As you saw above, this syntax is not super pleasant to deal with. That's why Pongo aims to do it for you.

How is it different than FerretDB?

FerretDB plugs into the native MongoDB protocol, which allows it to be used as MongoDB and connect to tools like Mongo UI, etc. Yet, it requires running a proxy.

Pongo operates on a different layer, translating the MongoDB API directly into SQL in the library code. This can allow easier serverless integrations, such as sharing a connection pool with other PostgreSQL-based tools, etc. Of course, it won't allow using native tools based on the MongoDB network protocol.

Pongo's goal is not to replace Mongo but to reuse its muscle memory and bring the PostgreSQL capabilities and superpowers into the Node.js land.

Is it production ready?

What's there is safe to use, but it's far from being 100% compliant with MongoDB. Pongo is a fresh project, so some stuff can be missing.

Support

If you'd like this project and want us to deliver more and faster, feel invited to join the group of our Github Sponsors.

By doing so, you're helping to make our work on it sustainable and continuing our efforts so we can support your products.

** Bronze Sponsors**

  • productminds
  • Lightest Night

Contribution

Pongo is a community project, so once you find something missing or not working, we encourage you to send us a GH issue or Pull Request extending the support or test coverage! Check also Contributing guide

AI stance

Pongo isn't vibe-coded. We use a mix of regular coding and agent-assisted work, but people make the design decisions. Every change is reviewed, understood, and validated by a person before it lands.

We don't mind contributors using agents either, as long as their contributions follow the contributing guide. The rule is simple: you vibe it, you own it. If you submit a change, you must understand it, stand behind it, and be able to explain, test, and fix it. The contribution is yours, not the tool's, so we don't accept generative AI tools as authors or co-authors.

Please don't submit AI slop. Generic, unreviewed, or needlessly verbose generated issues, pull request descriptions, or review comments may be ignored or closed when they create more work than value.

If you think something is missing or want to get some features faster, I'm happy to take sponsoring to prioritise it. Feel free to contact me - we'll find a way to help you!

Code of Conduct

This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScriptmogodbnodejspostgresqltypescript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类数据库
定价开源

> 相关工具

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库