How to: self-host MongoDB on

I was curious about how to host MongoDB on using our machines platform. The above repo is somewhat of a template for that. No this is not official MongoDB, this is just a side project of mine.

Instructions on the README, feel free to use/clone it and let me know if you have ever tried MongoDB or another on Fly before, I’d love to hear your thoughts.

You’ll notice there’s some manual work when first creating the cluster and when horizontally scaling things. I’m sure there are clever ways to detect cluster changes and make everything go smoothly (we do that with our Postgres, repgmr at least does that) but I’m comfortable with running manual commands when manually scaling things for now.


Hi Mr. @lubien.
I thank u for the example and I followed the github readme. It was deployed successfully but I tried to connect it with the provided URI mongosh "mongodb://" --username admin --authenticationDatabase admin.

I got an error.

MongoNetworkError: connect ECONNREFUSED

I’m just testing how I can self host a mongodb cluser. I believe I need to get a dedicated IP4?

Edited: I founder another github GitHub - bogordesaincom/mongodb-fly: Deploy Mongodb Docker with Fly. I might have a look at it later.

Another questions about horizontal scaling that u mentioned in the repo.

Horizontal scale

All you need to do is clone the primary then run a setup-command inside your primary node.

fly m clone PRIMARY_MACHINE_ID --region gig fly ssh console -s -C "setup-machine NEW_MACHINE_ID" # run this on your primary

  1. I wonder if all vms with mongodb get replicated?
  2. I wonder how I could manage backups, snapshots like fly postgres.

I added a dedicated ip4 and tried to connect it via

mongosh "mongodb://"

MongoServerSelectionError: Server selection timed out after 2000 ms

I wonder what it means.

Update: I used this guideline GitHub - bogordesaincom/mongodb-fly: Deploy Mongodb Docker with Fly. It worked.

1 Like

@milimyname glad you ended up finding something that works for you.

If anyone else is giving this a try and runs into ECONNREFUSED when connecting from a terminal, try this command first to forward your MongoDB app’s port to your local machine:

fly proxy 27017 -a <mongodb-app-name>
(More on fly proxy here: fly proxy · Fly Docs)

Then, in another terminal window, retry connecting via mongosh <URI>. You should also be able to connect using MongoDB Compass!

1 Like

Thank u, @leslie!

I wonder if there’d be an official documentation about Mongodb like Postgres?

I don’t believe that’s something come up in the short future, we would be looking for partners to provide easy mongo integration. This repo was just a weekend project of mine

1 Like

Hi Mr. @lubien.

Thank u for the reply and I’ll still use for my use case. It’d be a prod app but it is fine. I can always roll it back to MongoDB Atlas.

It is great to hear that fly devs use their platform for their side projects!

1 Like