elegant-king-24193
10/19/2023, 6:35 AMfresh-football-47124
elegant-king-24193
10/19/2023, 7:52 AMwhite-fireman-22476
10/19/2023, 8:32 AMcuddly-finland-73937
10/19/2023, 1:45 PMlet 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
?authSource=admin&directConnection=true&serverSelectionTimeoutMS=5000&tls=true&tlsCAFile=%2Fusr%2Flocal%2Fsrc%2Fapp%2Fglobal-bundle.pem&retryWrites=False
white-fireman-22476
10/19/2023, 6:22 PMcuddly-finland-73937
10/19/2023, 8:51 PMelegant-king-24193
10/20/2023, 7:46 AMwhite-fireman-22476
10/20/2023, 7:46 AMcuddly-finland-73937
10/20/2023, 10:01 AMwhite-fireman-22476
10/20/2023, 2:07 PM