On Mon, 07 Nov 2016 10:21:58 GMT, ChangLong wrote:

On Mon, 07 Nov 2016 05:02:47 GMT, Uiy Uiy wrote:

On Sat, 05 Nov 2016 01:29:10 GMT, ChangLong wrote:

On Wed, 02 Nov 2016 00:55:55 GMT, Uiy Uiy wrote:

If I try to connect to a mongoDB in a static this, it fails.

I suppose that vibe.d has not initialized the mongoDB driver.

It simplifies my code to initialize module level global database variables in static this but this is non-compliant with vibe.d. While I could spawn a thread and spin for a bit until vibe.d has run, this is not the optimal solution.

MongoClient client;
MongoDatabase db;
MongoCollection collection;
static this()
{
	client = connectMongoDB("127.0.0.1");
	db = client.getDatabase("Test");	
	collection = client.getCollection("Test.test");
}

Any ideas?

The event loop is not running yet in static this.

So, the question is how to get it to run before(order the calls of the static this's). There is obviously a dependency issue.

If it used in web server, you can use connect pool or create new one for each request.

if not from web server, you can run it from the task delegate.

Where do I find out how to do this? (both cases)