Microsoft has announced the open-sourcing of the DocumentDB project, which can be used as a standalone NoSQL database, a platform for building custom storage systems, or as an extension for storing data in BSON format within PostgreSQL. In practice, DocumentDB is used by Microsoft as the foundation for the product 'Azure Cosmos DB for MongoDB', providing a MongoDB-compatible interface for document-oriented databases. The project code is written in C and is distributed under the MIT license. The DocumentDB engine is implemented as an extension to PostgreSQL.
Similar to MongoDB, DocumentDB uses a JSON-like BSON (Binary JSON) format for storing structured documents, allowing for the creation of hierarchical structures where documents and arrays can be embedded within other documents and arrays. A key difference from JSON is the use of binary representation for data serialization. The project supports both NoSQL operations for creating, reading, updating, and deleting BSON data and an API for standard PostgreSQL (DocumentDB can be viewed as a variant of PostgreSQL with BSON support). DocumentDB can utilize full-text search capabilities and operations on vector and geospatial data types.
The project comprises two components:
- pg_documentdb_core — an extension to PostgreSQL that implements the BSON type and operations for handling BSON data within PostgreSQL.
- pg_documentdb — a publicly accessible DocumentDB API with basic operations for handling documents in BSON format, processing queries, and managing indexes.
The first release of DocumentDB provides support for CRUD operations (create, read, update, delete), indexes for individual BSON fields, full-text search indexes (compatible with RUM), vector and geospatial queries (compatible with pg_vector and postgis), and capabilities for query formation and data aggregation in BSON.
The project FerretDB has transitioned to using DocumentDB, which develops a MongoDB-compatible database based on PostgreSQL. FerretDB allows for a complete switch from the proprietary document-oriented MongoDB database to an entirely open software stack based on PostgreSQL, without any changes to application code. The necessity to replace MongoDB arises from its transition to the SSPL license, which is based on the AGPLv3 license but is not open, as it includes a discriminatory requirement to provide not only the application's code but also the source texts of all components involved in delivering the cloud service under the SSPL license.
Initially, FerretDB's operation involved translating MongoDB queries into SQL queries for PostgreSQL, but starting with FerretDB version 2.0, which is in release candidate stage, the PostgreSQL extension DocumentDB is used to support the BSON format. The switch to using DocumentDB has boosted FerretDB's performance by more than 20 times for certain types of load. Other innovations in FerretDB 2.0 include improved compatibility with MongoDB, replication capability, and support for vector search. The FerretDB code is written in Go and is distributed under the Apache 2.0 license.
Source: opennet.ru
