Version v3.7.0 of the documentation is no longer actively maintained. The site that you are currently viewing is an archived snapshot.
For up-to-date documentation, see the latest version.
FerretDB is an open-source MongoDB wire protocol compatible middleware that allows you to use PostgreSQL as a drop-in replacement for MongoDB.
It enables applications that rely on MongoDB’s wire protocol to work seamlessly with PostgreSQL, providing a bridge between the two databases.
To enable FerretDB, you’ll need the FerretDB patched documentdb extension, which is also available in the Pigsty repository.
The latest combo is FerretDB 2.7 and DocumentDB 0.107.0.
./configure -c mongo # Use FerretDB / DocumentDB config template./install.yml # Install, for production deployment please modify passwords in pigsty.yml first
For production deployment, please ensure to modify the password parameters in the pigsty.yml configuration file before running the installation playbook.
Configuration
pg-meta:hosts:10.10.10.10:{pg_seq:1, pg_role:primary }vars:pg_cluster:pg-metapg_users:- {name:mongod ,password:DBUser.Mongo ,pgbouncer:true ,roles:[dbrole_admin ] ,comment:ferretdb super user ,superuser:true}- {name:dbuser_meta ,password:DBUser.Meta ,pgbouncer:true ,roles:[dbrole_admin ] ,comment:pigsty admin user }- {name:dbuser_view ,password:DBUser.Viewer ,pgbouncer:true ,roles:[dbrole_readonly] ,comment:read-only viewer }pg_databases:- {name:meta, owner:mongod ,baseline:cmdb.sql ,comment:pigsty meta database ,schemas:[pigsty] ,extensions:[documentdb, postgis, vector, pg_cron, rum ]}pg_hba_rules:- {user:dbuser_view , db:all ,addr:infra ,auth:pwd ,title:'allow grafana dashboard access cmdb from infra nodes'}- {user:mongod , db:all ,addr:world ,auth:pwd ,title:'mongodb password access from everywhere'}node_crontab:['00 01 * * * postgres /pg/bin/pg-backup full']# make a full backup every 1am# DocumentDB Settingspg_extensions:[documentdb, citus, postgis, pgvector, pg_cron, rum ]pg_libs:'pg_documentdb, pg_documentdb_core, pg_cron, pg_stat_statements, auto_explain'# add timescaledb to shared_preload_librariespg_parameters:{cron.database_name:meta }
You can access FerretDB using MongoDB connection strings with any MongoDB driver in any language. Here’s an example using the mongosh CLI tool:
$ mongosh
Current Mongosh Log ID: 67ba8c1fe551f042bf51e943
Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.4.0
Using MongoDB: 7.0.77
Using Mongosh: 2.4.0
For mongosh info see: https://www.mongodb.com/docs/mongodb-shell/
test>
mongosh 'mongodb://dbuser_meta:[email protected]:27017/meta'# Business admin usermongosh 'mongodb://dbuser_view:[email protected]:27017/meta'# Read-only user
Quick Start
You can connect to FerretDB and use it as if it were a MongoDB cluster.