Setting up Heroku with mongodb without using MLAB - mongodb

Most of the documentation Ive seen only covers using mLab as a service for mongodb on heroku,
I would like to use mongoDB locally on the heroku server is this possible?

Heroku dynos use an ephemeral filesystem. This means that you cannot run a database on a Heroku dyno. All of the data will be lost whenever your process restarts. Your process restarts at least once every day, whenever you deploy new code, whenever you change config variables, or whenever you update add-ons.
You can read more about Heroku's ephemeral filesystem here: https://devcenter.heroku.com/articles/dynos#ephemeral-filesystem
You can read more about dyno restarts here: https://devcenter.heroku.com/articles/dynos#restarting
So you will have to use a Heroku Add-on or a third-party service to add persistence to your application.
This doesn't mean you have to use the mLab Add-on. If you have your own MongoDB database, you can still connect to that in your application. You can add the connection string as a config variable and connect to it in the same way you would connect to an mLab Add-on.

Related

Google Cloud postgres – connecting from Heroku

I was using Postgres addon on Heroku and was connecting to the database using DATABASE_URL env var.
I now need to switch to Google Cloud Platform Postgres. I've created an instance and successfully added my local connection to the Authorised networks. Yet it seems that Heroku does not provide a static IP for its apps.
My question is then – is it possible to connect my Heroku app to a Postgres database from the Google Cloud Platform? If yes – what's the best way to do it?
You will want to run the Cloud SQL Proxy alongside your application. This will allow your Heroku App to connect to Cloud SQL without the need to worry about changing and adding IPs to your Authorized Networks.
This thread might be useful for your use-case. Node and Cloud SQL with Heroku

How to connect mongodb in contanier

I deploy a mongodb in a container. and I also successfully connected to mongodb when my backend runs in the local environment. However, when I tried to move the backend to a container as well, it cannot connect mongodb anymore. The connection string remains the same but it failed.
The error shows that mongodb cannot find the user. However, in my local environment, the same connection string works.
After my googling, most guys said I need to change authSource. I have tried to change authSource to admin, it doesn't work even in my local environment. And I am sure the user exists in my admin database. not in api_dev_db. One wired thing is I can connect to mongodb in my local environment but not work in docker.
Could you kindly help me out?
Here I post some pictures.
These are the env variables I defined in my local environment and they work
This is how I deploy backend service
This is my backend dockerfile
This is the error when I deploy backend in container
This is how I initial mongodb
The problem is I need to remove '' in env variable, which is MONGO_URL=mongodb://api_user:api1234#mongodb:27017/api_dev_db?authSource=api_dev_db

Run local database with Heroku

What I need to know if I use service to create PostgreSQL in Heroku, can I set up this database locally in development mode?
I couldn't find in their documentation on how to do this.

How to persist mongodb when deploying with meteor?

When I meteor deploy my app, it seems to create an entirely new mongodb instance. I'd like to be able to deploy with the current mongodb have locally.
Same goes the other way -- I'd like to be able to download the mongodb back to my localhost after it has been deployed.
For clarification, I'd really like to know the follow:
1) how to deploy with a fresh mongodb
2) how to deploy to an existing deployed app without overwriting the old mongodb
3) how to download/sync mongodb locally with the existing deployed app
4) how to make local backups of mongodb
You can perform a mongo dump using meteor mongo to export your local database and deploy your app using Meteor Up which should also allow you to automate the database import and deployment process.
"Meteor Up (mup for short) is a command line tool that allows you to deploy any meteor app into your own server."
You can stop the mongodb service and start a mongod instance in a separate terminal, by just typing mongod. This will let you monitor what's happening on the mongodb instance that you just started.
Open another terminal and do export MONGO_URL=mongodb://localhost:27017/nameOfDBgoesHere
This will create a new DB named "nameOfDBgoesHere" and it won't overwrite what you currently have, unless you name it with the same name.
After that just start meteor by typing meteor in your program's folder. In the mongod terminal that you opened you should see some connections opening.
By default mongodb creates it's DB files in /data/db. If you have another meteor app and follow the same steps in another terminal, while keeping the name of the DB you specified in the MONGO_URL you will just connect to it from that app - without overwriting anything.
As for the syncing with a deployed app and the local backups of mongo - it seems like something that the mongodb website covers, but maybe someone can chime in here. Not sure if there is a meteor specific, easy way of doing this.

Heroku Postgres configure data center location

My understanding is that Heroku Postgres runs on top of AWS. Is it possible to configure which datacenter your database is running in? I'm also wondering if the database files are stored on an encrypted filesystem.
Yes, Heroku runs on AWS. But you are not able to specify which datacenter to run your database. For encryption look at http://www.postgresql.org/docs/current/static/pgcrypto.html.
Heroku runs out of Amazon US-East - once you've add a postgres db to your app heroku config will give you the database connection URL which you would be able to tracert on to see where it is