Use FerretDB with Neon
Add MongoDB compatibility to your Neon database with FerretDB
FerretDB is an open source document database that adds MongoDB compatibility to other databases, including Postgres. By using FerretDB, developers can access familiar MongoDB features and tools using the same syntax and commands for many of their use cases.
In this guide, you'll learn about FerretDB and how you can add MongoDB compatibility to your Neon Postgres database.
Advantages of FerretDB
The benefits of using FerretDB include:
FerretDB gives you access to the syntax, tools, querying language, and commands available in MongoDB for many common use cases. MongoDB is known for its simple and intuitive NoSQL query language which is widely used by many developers. By using FerretDB, you can enable Postgres databases like Neon to run MongoDB workloads.
For related information, see MongoDB Compatibility - What's Really Important?
As an open source document database, you won't be at risk of vendor lock-in. Since MongoDB's license change to Server Side Public License (SSPL), there's been a lot of confusion regarding what this means for users and what it would mean for their applications. According to the Open Source Initiative – the steward of open source and the set of rules that define open source software – SSPL is not considered open source.
FerretDB is licensed under Apache 2.0, makes it a good option for users looking for a MongoDB alternative.
Multiple backend options
FerretDB currently supports Postgres and SQLite backends, with many ongoing efforts to support other backends. Many databases built on Postgres can serve as a backend for FerretDB, including Neon. That means you can take advantage of all the features available in the backend of your choice to scale and manage your database infrastructure without fear of vendor lock-in.
To learn more, see Understanding FerretDB.
The prerequisites for this guide include the following:
- A Neon account and project. See Sign up.
- A database. This guide uses a database named
ferretdb. It's easy to create a database in Neon. See Create a database for instructions.
- Docker. For instructions, see Get Docker. To verify your installation or check if you already have Docker installed, you can run
mongoshcommand-line tool. For installation instructions, see Install mongosh. If you are a macOS user, you can quickly install with Homebrew:
brew install mongosh.
Retrieve your Neon database connection string
From the Neon Dashboard, retrieve the connection string for your
ferretdb database from the Connection Details widget.
Your database connection string will look something like this:
Run FerretDB with Neon via Docker
Execute the following command to run FerretDB in a Docker container and connect it to your Neon Postgres database (
Test via mongosh
From another terminal, test to see if the FerretDB instance is connected to your Neon database using
mongosh. To connect via
mongosh, you will need a connection string. Use the credentials for your Neon database connection string.
So in this case, the MongoDB connection string will be:
This will connect you directly to the FerretDB instance where you can run MongoDB commands.
You are now directly connected to your
Insert documents into FerretDB
mongosh, you can now insert some documents into your FerretDB instance directly from the
ferretdb> prompt shown above. You are going to insert two basketball player documents into a
Now, when you run
db.players.find(), it should return all the documents stored in the collection:
Update a record in FerretDB
Next, you need to update the "Jordan" record to reflect his current position as a
SF. To do this, we can just run an
updateOne command to target just that particular player:
Query the collection to see if the changes have been made:
You can run many MongoDB operations on FerretDB. See the list of supported commands in the FerretDB documentation.
View your database on Neon
In addition to a document database view of the collection in FerretDB, you can also view and query the data in Neon.
To view your current documents, go to the Neon Dashboard and select Tables from the sidebar. Then, from the Schema menu, select
ferretdb. FerretDB stores the documents in Postgres as JSONB data.
Get started with FerretDB
FerretDB lets you run MongoDB workloads on relational databases. This flexibility means you can easily add MongoDB compatibility to your Neon Postgres database while avoiding vendor lock-in and retaining control of your data architecture.
To get started with FerretDB, check out the FerretDB Get Started docs.
Last updated on