On 13/05/2022 5:18 PM, MichaelBi wrote:
i have code here:
auto uri = environment.get("MONGODB_URI");
MongoClient conn = connectMongoDB(uri);
MongoDatabase eqpdb = conn.getDatabase("MbEqpHeroku");
the "MONGODB_URI" showed above already put into heroku's app config as
the 'key' and there is a paired 'value'. so the uri is to extract the
value which is to use for app to establish mongodb connection.
and above code with error msg here: Error: `getenv` cannot be
interpreted at compile time, because it has no available source code
That part of the code is probably fine.
Basically you have to be careful that:
auto uri = environment.get("MONGODB_URI");
Isn't being executed during compilation.
Stuff that typically cause this is anything that initializes a variable.
Globals:
shared Foo foo = Foo(...);
Class fields:
class Foo {
Bar bar = Bar(...);
}