How to deploy with mongo db deployment?

How can I deploy a repl (based on typescript) with a mongo db backend? I know I can use a 3rd party service provider to do this but what is the replit recommended way?

1 Like

The Replit recommended way is to use Replit Database (docs: For Mongo DB, I think it’s more complicated to set up, I think.

Hopefully, I’m not being clueless right now, but I’m pretty sure that Postgres (if it’s a database) is the TRUELY Replit recommended way because it’s paid (Reason: :dollar::dollar::dollar:). Documentation here: and

Notice how I answered “the Replit recommended way for a database.” You must regard a different post for how to set up Mongo DB if you’re still looking to do that.

1 Like

I appreciate your reply. It inspired me to ask what Ghostwriter thinks about this question and as is quite useful I will paste it here and try this next.

You can create a MongoDB database in Replit by following these steps:

  1. Click on “Create new Repl” on your Replit dashboard
  2. Choose your preferred language (Node.js, Python, etc.) and template for your project
  3. Open your terminal/console and install the mongodb package using npm:
npm install mongodb
  1. In your code, create a new MongoClient object and pass in your MongoDB connection string. You can find your connection string in the Atlas dashboard.
  2. Use the db method of the MongoClient object to get a reference to your database, and the collection method to get a reference to a specific collection in your database.

Here’s an example of how to connect to a MongoDB database in Replit using Node.js:

const MongoClient = require('mongodb').MongoClient; const uri = 'mongodb+srv://<username>:<password>@<cluster><dbname>?retryWrites=true&w=majority';const client = new MongoClient(uri, { useNewUrlParser: true, useUnifiedTopology: true }); client.connect((err) => {  const collection = client.db("test").collection("devices");  // perform actions on the collection object  client.close();});

Replace <username>, <password>, <cluster>, and <dbname> with your MongoDB credentials.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.