On Wed, 11 Sep 2013 16:49:14 GMT, Craig Dillabaugh wrote:
On Wed, 11 Sep 2013 02:26:25 GMT, David Eagen wrote:
On Tue, 10 Sep 2013 17:50:57 GMT, Craig Dillabaugh wrote:
- MongoClient mongo_client;
- auto imagelst = mongoclient.getCollection("mydb.images");
You need to get your MongoClient object from the connectMongoDB() function like this:
MongoClient mongo_client = connectMongoDB(url);
The url should be something like: mongodb://localhost/mydb
This doesn't seem to work either. It hangs my server. To test things out I have the function:
void listImages(HTTPServerRequest req, HTTPServerResponse res) { logInfo("Entering list images."); g_mongo_client = connectMongoDB("mongodb://localhost"); auto images = g_mongo_client.getCollection("mydb.images"); foreach( img; images.find() ) { logInfo("Image: %s", img.toJson() ); } res.renderCompat!("images.dt", HTTPServerRequest, "req")(req); }
If I comment out the connectMongoDB() line the server will list all the records in "mydb.images", but it still hangs/crashes when trying to generate the images.dt template. If I add a connectMongoDB line to my template then it hangs, if I use the same code as I have in my listImages(...) function, without connectMongoDB(), then it crashes as described in the original post.
*Entering list images" always gets logged, so I am assuming that it is connectMongoDB() that causes it to hang.
I wouldn't really explain why it hangs, but it may be that you hit https://github.com/rejectedsoftware/vibe.d/issues/289 and need to replace "localhost" with "127.0.0.1". Without a connectMongoDB
call it would be a mystery, though, if it still works. g_mongo_client
would contain a null pointer after all.
If you are on Windows, you can also add "subConfigurations": {"vibe-d": "win32"}
to your package.json to use the win32 driver, which doesn't have the "localhost" issue.