Reputation: 2585
After successfully deploying on localhost (0.0.0.0:8080) While I pushed the code to git for heroku, I am getting error on heroku.
Cannot connect to MongoDB
Process exited with status 0
Inside package file I added
dependencies: [
.Package(url: "https://github.com/vapor/vapor.git", majorVersion: 1, minor: 1),
.Package(url: "https://github.com/OpenKitten/MongoKitten.git", majorVersion: 3)
],
Inside main.swift the program exists on this line
let mongoDatabase = try Database(mongoURL: "mongodb://localhost/mydatabase")
Additional info: I believe that on commit there is something which is left out by the SourceTree. As the same code is also not working after checkout on a different machine. And the code is compiling perfect.
Upvotes: 1
Views: 569
Reputation: 1539
here is an info how to get the DATABASE_URL for postgres but it shold be the same for mongo DB:
heroku addons:create heroku-postgresql:hobby-dev
after some minits preparation:
heroku config
there shold be the url
in your Procfile
(you created with vapor init
) you can add the db url:
our text editor and update it so that looks like the below.
web: App --env=production --workdir="./"
web: App --env=production --workdir=./ --config:servers.default.port=$PORT --config:postgresql.url=$DATABASE_URL
this is the db url we add --config:postgresql.url=$DATABASE_URL
Save Procfile
and type git push heroku master
after some time it should working.
you should change the name postgresql.url
to your mongo db confog name (depending which mongo addon you use)
Upvotes: 2