FerretDB is a document database that uses similar commands, drivers, and tools to those of MongoDB for storing data. Unlike relational databases, which use tables, rows, and columns to define the schema of the database, document databases use key-value pairs to build the structure of a document.
Document databases can collect, store, and retrieve data in a variety of data types. In FerretDB, data is stored as BSON - a binary representation of JSON - so you can store more types of data than in regular JSON. However, we do not currently support 128-bit decimal floating point values.
Before inserting data into a document, you do not need to declare a schema. That makes it ideal for applications and workloads requiring flexible schemas, such as blogs, chat apps, and video games.
Documents are self-describing records containing both data types and a description of the data being stored. They are similar to rows in relational databases. Here is an example of a single document:
The above data is stored in a single document.
FerretDB follows almost the same naming conventions as MongoDB. However, there are a few restrictions, which you can find here.
For complex documents, you can nest objects (subdocuments) inside a document.
In the example above, the
name field is a subdocument embedded into a document.
(.) are used to reference a field in an embedded document or its index position in an array.
Dot notations can be used to specify or query an array by concatenating a dot
(.) with the index position of the field.
When using dot notations, the field name of the array and the specified value must be enclosed in quotation marks.
For example, let's take the following array field in a document:
animals: ["dog", "cat", "fish", "fox"]
To reference the fourth field in the array, use the dot notation
Here are more examples of dot notations on arrays:
To reference or query a field in an embedded document, concatenate the name of the embedded document and the field name using the dot notation.
Take the following document, for example:
To reference the
city field in the embedded document, use the dot notation
For dot notation examples on embedded documents, see here:
Collections are a repository for documents. To some extent, they are similar to tables in a relational database. If a collection does not exist, FerretDB creates a new one when you insert documents for the first time. A collection may contain one or more documents. For example, the following collection contains three documents.
For PostgreSQL, FerretDB converts MongoDB drivers and protocols to SQL, where we convert MongoDB bson to jsonb and store it as a value in a row. Read more on jsonb in PostgreSQL.
In Tigris case, we convert MongoDB BSON to Tigris data based on the Tigris model. There are a few differences in how data is stored in PostgreSQL and Tigris. Please check here for more details on the differences.
FerretDB is still under development and not currently suitable for production-ready environments.