How to connect Glitch to mlab?

How to connect Glitch to mlab?
0

#1

So I’ve been struggling with the FCC back end projects but been making slow progress trying to understand everything. One thing I’ve been stuck on once I tried to integrate MongoDB on Glitch. I set up an account on mlab and tried to use Glitch console commands to connect my database to my project but that’s not working for me. Is there an easy way to do it?


#2

In your mLab db’s page, there’s a URI that you can use to connect to that db. Copy that, then paste it in the .env file (be sure to fill in a db username and password) like this:

MONGODB_URI="mongodb://uri.to.db"

Then you can use it in your code like this (as if it’s a regular object property):

// assuming you're using Mongoose
mongoose.connect(process.env.MONGODB_URI, {useMongoClient: true});

#3

I know this comes late, but this worked perfectly for me. Thank you!


#4

Now I’m currently having trouble with the Image Search Abstraction Layer project, specifically with connecting to the Google custom search engine. Do I need to put the google API key and the custom search ID in the .env file as well? Again I am using Glitch for this project. Thanks in advance.


#5

Yes, API keys, secrets, IDs, etc. should be set as environment variables.


#6

LIFESAVING!!! Thanks a mil!!