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.