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?

1 Like

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> @mayumi-db-gt3cf.mongodb.net/test?retryWrites=true&w=majority”
(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

1 Like

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

Hey @Infinity1231
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: So set the IP to 0.0.0.0/0 to whitelist all the networks.

You need not use mongoose to work with MongoDB as @ayoubmadrid mentioned.
However, it is recommended to do so.

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 dtabase 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);
  client.close();
});

If you’ve 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.
If you have any issues, feel free to mention me.

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: