What is document database (MongoDB-compatible)
PolarDB for MySQL provides full compatibility with MongoDB, allowing your applications to connect seamlessly through standard document database drivers such as pymongo for Python, mongoose for Node.js, and the MongoDB driver for Go, without modifying your business code. Beyond API compatibility, this feature integrates the core enterprise capabilities of PolarDB, including elastic scaling in seconds, massive data storage, and finance-grade high availability, delivering a cost-effective and high-performance NoSQL solution.
How it works
PolarDB for MySQL achieves MongoDB API compatibility through the collaboration of the database proxy layer and compute nodes. Understanding how this works helps you make the most of this feature.
-
Database proxy layer (Proxy)
The proxy layer is the core of protocol conversion. It receives BSON requests from clients, performs authentication, protocol parsing, and request routing. The proxy layer then converts document database operations into SQL statements that MySQL can process and intelligently dispatches them to the most appropriate compute node. This design decouples protocol compatibility logic from the database kernel, allowing you to reuse the mature connection pooling, load balancing, and read/write splitting capabilities of PolarDB.
-
Database compute nodes
Compute nodes use a high-availability architecture with one primary node and multiple read-only nodes. The Enterprise Edition supports up to 15 read-only nodes, and the Standard Edition supports up to 7. The primary node handles all write operations, and the read-only nodes share the read workload. The compute layer is built on the standard MySQL kernel and adapts to minor differences in BSON types such as collations, operators, and indexes. This minimal-modification design ensures maintainability and enables quick adoption of MySQL community releases. You do not need to create databases or tables or define schemas, which provides a collection management experience consistent with document databases.
Benefits
-
Smooth migration and ecosystem compatibility: Highly compatible with the MongoDB API and its ecosystem. Your existing applications and business systems can connect directly without code refactoring, while you continue using NoSQL development practices. DTS migration is also supported.
-
Unified data platform: The same data supports both flexible NoSQL reads and writes and complex SQL queries and analysis, bridging operational and analytical workloads.
-
Elastic scaling and cost-effectiveness: Built on a compute-storage decoupled architecture.
-
Storage is billed based on actual usage, up to 1 PB. Multiple compute nodes share the same storage, and read-only nodes can be added in minutes regardless of storage volume, providing strong scalability.
-
Compute nodes can be resized on demand in minutes. You can also enable the Serverless feature on a cluster with fixed specifications for elastic scaling in seconds using PCUs (PolarDB Capacity Units), effectively reducing resource costs.
-
-
High performance and low latency: Read-write (RW) and read-only (RO) nodes share the same storage. Data replication does not require oplog synchronization, which saves storage and compute overhead and delivers higher performance with lower data latency on read-only nodes.
-
Intelligent proxy for transparent scaling: The proxy layer provides automatic read/write splitting for transparent scaling, so applications do not need to distinguish between read and write operations. The built-in connection pool effectively handles high-frequency short-lived connections and large numbers of persistent connections. Connection persistence supports seamless specification changes and online switchover.
-
Enterprise-grade reliability: Built on high-performance distributed shared storage and the mature PolarDB high-availability architecture, with second-level data snapshots to ensure data security and business continuity.
Scope of application
Before you use document database compatibility with the MongoDB protocol, make sure that your cluster meets the following version requirements:
-
Kernel version: MySQL 8.0.2, and the minor kernel version must be 8.0.2.2.36 or later.
-
PolarProxy version: 2.9.22 or later.
-
Other limits: Serverless clusters do not currently support the document database compatibility feature.
You can go to PolarDB console and view the versions on the page of your cluster. If the versions do not meet the requirements, upgrade the minor version.
Billing
Document database compatibility with the MongoDB protocol does not incur additional charges. You only pay for the PolarDB for MySQL cluster itself. For more information, see Billing overview.
What to do next
After you understand the feature overview, follow the instructions in Use document database (MongoDB-compatible) to create a cluster, configure an account, and verify the initial connection.