How to launch mongo database locally?

I’ve never worked with MongoDB and have no idea how to launch it in Glitch. Can someone give me instructions?


u mean access it from glitch?
what coding language ur using?

Yes, and the language is JavaScript

i use mongoose

const mongoose = require(‘mongoose’)
mongoose.connect(process.env.MONGO, {
useNewUrlParser: true,

replace porocess.env.MONGO with

“mongodb+srv:// <your username> : <your password>”
(note that the username and the password are not ur account but the ones from access managment)
(and u need to enable white list IP addresses from everywhere in network access or get every IP adress from glitch and fill them there)
if u need more about it just go watch a youtube video or ask me


Thank you, I will try this and let you know.

Hey @Daksh777
Since you’ve never worked with MongoDB, I’d recommend you to watch a few tutorials about MongoDB and basics. I’ve been using MongoDB for quite a time, so here’s are a few things, I’d like to tell you:

You can register an account for MongoDB Atlas for cloud storage. (Watch tutorials on how to create cluster and connection).
You will most likely have issues with whitelisting: You can set the IP address to to whitelist all the networks.
You need not use mongoose to work with MongoDB as @ayoubmadrid mentioned.
Once you have received your connection string from the website.

You can go ahead and process further with the example given below:

const MongoClient = require('mongodb').MongoClient;
const url = 'mongodb://localhost:27017'; // replace this with the connection string, make sure to replace <password> with the database password
const name = 'myproject'; // replace this string with the db name you desire.
MongoClient.connect(url, function(err, client) {
  if (err) throw err;
  console.log("Connected successfully to server");
  const db = client.db(name);

If you face any trouble, feel free to mention me with the issue.


Just For Info, As far as I have tried, one cannot access MongoDB at localhost from Glitch.

Indeed, they cannot. However, you can use MongoDB Atlas for cloud storage.

MongoDB will not run locally. This is because MongoDB will eat up all of your storage pretty much instantly! Also, MongoDB wouldn’t be able to run as a service as the Glitch containers don’t allow access to sudo.

Hope this helps!

I’ll try your method and let you know if it works.

Make sure to change the connection string and follow all the steps properly.
If it doesn’t work or you face any issue, feel free to mention me.

Sure. As soon as I get back to my PC, I’ll try it :smiley:

i am confused about what ip adress should i set

Hi there @shinchan-pb-xi!
If you have set up a MongoDB database on your own PC you can use port forwarding and then connect to your external IP on Glitch. If this is too confusing, I really like MongoDB Atlas which will give you a connection string/url to put in the code
Hope this helps :slight_smile:

Also you can use a database adapter (like Endb) along with the database of your choice and it’ll be even more easier to play with databases.