Hello everybody. A bit of a weird question here. I...
# ask-questions
e
Hello everybody. A bit of a weird question here. I was wondering how I would edit the source code of Growthbook and create a new image of it? Long story short, the way growthbook accepts a MONGODB_URI does not really work for my use case, and I would prefer to edit the source code to accept username, password, and endpoint, and then growthbook builds the URI. I have tried editing the source code and building a new image, but it doesn't seem to work properly and I'm not really sure why. Any help is appreciated. Thanks :)
1
f
did you follow the contributing guide?
you could also open a pull request with the changes to support another way of connecting to MongoDB
but I believe the connection string does support user/password
e
I will look into the contributing guide. As far as I've seen I need to send growthbook a complete MONGODB_URI as an ENV variable. This poses issues when using AWS CDK. I'd like to be able to send the parts that make up the URI, and have growthbook build it. But I will look into the contributing guide and see if I can figure out a solution. Thanks 🙂
w
I think other people also have wished this. It does seem reasonable for us to support this, so if you do make a PR let me know and we will probably merge it.
c
I've seen a LOT of folks in Slack complaining about this problem
@helpful-application-7107 was checking with the GB team about any technical issues with this
@elegant-king-24193 This is my proposal based on your suggestion: https://github.com/growthbook/growthbook/compare/main...yepher:growthbook:feature/alt_mongo_credentials
Copy code
let MONGODB_URI = process.env.MONGODB_URI;

if (!MONGODB_URI) {
  // Check for alternate mongo db environment variables
  if (
    process.env.MONGO_DB_USERNAME &&
    process.env.MONGO_DB_PASSWORD &&
    process.env.MONGO_DB_HOSTNAME
  ) {
    MONGODB_URI = `mongodb://${process.env.MONGO_DB_USERNAME}:${process.env.MONGO_DB_PASSWORD}@${process.env.MONGO_DB_HOSTNAME}/growthbook`;

    // Add extra args if they exist
    if (process.env.MONGO_DB_EXTRA_ARGS) {
      MONGODB_URI += `?${process.env.MONGO_DB_EXTRA_ARGS}`;
    }
  }
}
So it will still prefer
MONGODB_URI
from env. But if that is not set, then if
MONGO_DB_USERNAME
and
MONGO_DB_PASSWORD
and
MONGO_DB_HOSTNAME
are set, then compose the
MONGODB_URI
from the individual values. If
MONGO_DB_EXTRA_ARGS
is set in the environment, then also set that as the query string part of the
MONGO_DB_URI
I think MONGO_DB_EXTRA_ARGS is important because in cases like DocumentDB you need to be able to provide stuff like
Copy code
?authSource=admin&directConnection=true&serverSelectionTimeoutMS=5000&tls=true&tlsCAFile=%2Fusr%2Flocal%2Fsrc%2Fapp%2Fglobal-bundle.pem&retryWrites=False
💯 1
w
@cuddly-finland-73937 Thanks so much for putting that together. I started a PR and left some comments. If you can address them, then I'd be happy to get this merged into main!
c
@white-fireman-22476 made some changes based on your comments
e
Thank you so much for taking the time to do this 😄
w
Sure... I made a few more comments on the PR. @cuddly-finland-73937.
c
@white-fireman-22476 added your suggestions
👀 1
w
I ended up closing that PR and opening my own with a few other changes: https://github.com/growthbook/growthbook/pull/1772. I'll let you know when it lands.
🎉 1
This has landed. You can see the new envs that the mongo uri can be generated from here: https://docs.growthbook.io/self-host/env
❤️ 3