I'm currently trying around with vibe.d and I'm confused about the MongoDB example:

import vibe.d;

MongoClient client;

void test()
{
        auto coll = client.getCollection("test.collection");
        foreach (doc; coll.find(["name": "Peter"]))
                logInfo("Found entry: %s", doc.toJson());
}

shared static this()
{
        client = connectMongoDB("127.0.0.1");
}

"client" is TLS but is initialized within a shared module consturctor, meaning that only the main thread will have a initialized db-connection. http://vibed.org/api/vibe.db.mongo.mongo/connectMongoDB says: "Thus, the MongoClient instance can - and should - be shared among all fibers in a thread by storing in in a thread local variable."

So wouldn't it make more sense that the MongoDB example initializes the "client" variable in a "static this()" instead of a "shared static this()" ?

Kind Regards
Benjamin Thaut

Reply via email to