Help, in vibe.d, how to get configure var of mongodb in heroku?

rikki cattermole rikki at cattermole.co.nz
Fri May 13 05:41:33 UTC 2022


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(...);
}



More information about the Digitalmars-d-learn mailing list