mongodb not using env variable for DATABASE_URL
See original GitHub issueI’m submitting a…
- Bug report
- Feature request
- Question
Current behavior
We’re running mongodb and have a database json that looks like this:
"defaultEnv": "dev", "dev": { "driver": "mongodb", "DATABASE_URL": {"ENV": "MONGO_URL"} },
It doesn’t seem to matter what ENV variable we set, we always get Error: database must be defined in database.json. If we manually set DATABASE_URL in our bash env, it works fine, but it doesn’t transform using MONGO_URL or really any env variable we set up. It seems like it’s just ignoring the environment transformation entirely.
Here’s the full error:
[ERROR] Error: database must be defined in database.json
at Object.exports.connect (/Users/Janiuk/repos/graphql-server/node_modules/db-migrate-mongodb/index.js:496:11)
at connect (/Users/Janiuk/repos/graphql-server/node_modules/db-migrate/lib/driver/index.js:93:12)
at Object.exports.connect (/Users/Janiuk/repos/graphql-server/node_modules/db-migrate/lib/driver/index.js:134:5)
at Object.exports.connect (/Users/Janiuk/repos/graphql-server/node_modules/db-migrate/connect.js:15:10)
at /Users/Janiuk/repos/graphql-server/node_modules/db-migrate/lib/commands/up.js:15:13
at tryCatcher (/Users/Janiuk/repos/graphql-server/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/Users/Janiuk/repos/graphql-server/node_modules/bluebird/js/release/promise.js:512:31)
at Promise._settlePromise (/Users/Janiuk/repos/graphql-server/node_modules/bluebird/js/release/promise.js:569:18)
at Promise._settlePromiseCtx (/Users/Janiuk/repos/graphql-server/node_modules/bluebird/js/release/promise.js:606:10)
at Async._drainQueue (/Users/Janiuk/repos/graphql-server/node_modules/bluebird/js/release/async.js:138:12)
at Async._drainQueues (/Users/Janiuk/repos/graphql-server/node_modules/bluebird/js/release/async.js:143:10)
at Immediate.Async.drainQueues [as _onImmediate] (/Users/Janiuk/repos/graphql-server/node_modules/bluebird/js/release/async.js:17:14)
at runCallback (timers.js:705:18)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5)
Expected behavior
DATABASE_URL should be properly populated using the ENV setting.
Minimal reproduction of the problem with instructions
Create a project with mongodb and db-migrate. Create a database.json looking something a-like-so:
{
"defaultEnv": "dev",
"dev": {
"driver": "mongodb",
"DATABASE_URL": {"ENV": "MONGO_URL"}
},
"staging": {
"driver": "mongodb",
"DATABASE_URL": {"ENV": "STAGING_DATABASE_URL"}
},
"uat": {
"driver": "mongodb",
"DATABASE_URL": {"ENV": "UAT_DATABASE_URL"}
},
"demo": {
"driver": "mongodb",
"DATABASE_URL": {"ENV": "DEMO_DATABASE_URL"}
},
"prod": {
"driver": "mongodb",
"DATABASE_URL": {"ENV": "PROD_DATABASE_URL"}
}
}
Run migrations using npx db-migrate up
. Watch the error listed above occur.
What is the motivation / use case for changing the behavior?
We’d love to see A: the environment variable properly populated when specifying it above and B: Not have to duplicate our environment variables with both MONGO_URL and DATABASE_URL with the same information.
Environment
db-migrate version: 0.11.6
plugins with versions:
db-migrate-mongodb: 1.5.0
db-migrate driver with versions: mongodb 3.4.6
Additional information:
- Node version: 10.15.1
- Platform: Mac
Others:
Issue Analytics
- State:
- Created 4 years ago
- Comments:14 (6 by maintainers)
Top GitHub Comments
OK. So, I experimented this morning, and I got it working properly. I’m certain it was a mix of both the engineer that implemented this initially reading the docs wrong, and then afterwards…me, also reading the docs wrong after viewing what we had and getting confused. There’s a section in which user and password are passed in via env variables, and I think that’s where the confusion came from. This is the block from the docs:
After our conversation last week, this morning I replaced our database.json config removing the “DATABASE_URL” value that’s in the original post above and used basically exactly what you suggested a few days ago that I initially misread as the same thing we had. Once I did that and removed the environment variable of DATABASE_URL, it worked exactly as it’s supposed to. So this was a case of poorly reading the docs and then myself poorly following up on it.
Thanks for your patience working through this user error issue. It’s much appreciated.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.