I am trying to retrieve records from a MongoDB database and display on a page using Diet templates.

I currently have the following template that causes a crash when I access it:

!!! 5
html
 head
  title Listing from Mongo DB
 body
  h Listing of images in my Mongo database.
  - import vibe.d;
  - MongoClient mongo_client;
  - auto image_lst = mongo_client.getCollection("mydb.images");
  - foreach(i; 0..4)
   - auto num = i;
   p 
    b= num
  p Thats all

Eventually my foreach() loop will print out the objects from the mydb.images collection, but I haven't gotten that far yet, because this template causes the server to crash with the error
Error: Program exited with code -11. If the line - auto image_lst = mongo_client.getCollection("mydb.images"); is removed then this works and prints out 0 to 3. I've tried the same Mongo code in my regular application and it works fine.

The first few stack frames from my backtrace:

#0 vibe.templ.diet.__T22compileDietFileCompatVVAyaa9_696d616765732e6474TC4vibe4http6server17HTTPServerRequestVAyaa3_726571Z.compileDietFileCompatV() (_arguments=..., _argptr=0x7ffff7ff82b0, 
    stream__=0x9cba58) at images.dt:7
#1  0x00000000005e3dff in vibe.http.server.HTTPServerResponse.__T12renderCompatVAyaa9_696d616765732e6474TC4vibe4http6server17HTTPServerRequestVAyaa3_726571Z.renderCompat() (this=0x9ab640, 
    _arguments_typeinfo=0x90d400 <TypeInfo_B37C4vibe4http6server17HTTPServerRequest.__init()>) at ../../.dub/packages/vibe-d-master/source/vibe/http/server.d:868
#2  0x0000000000566dc9 in app.listImages() (res=0x9ab640, req=0x99b620) at source/app.d:61
#3  0x000000000058a858 in std.functional.__T13DelegateFakerTPFC4vibe4http6server17HTTPServerRequestC4vibe4http6server18HTTPServerResponseZvZ.DelegateFaker.doIt() (
    this=0x566da0 <app.listImages()>, a1=0x9ab640, a0=0x99b620) at /usr/include/dmd/phobos/std/functional.d:705
#4  0x00000000005e5609 in vibe.http.router.URLRouter.handleRequest() (this=0x7ffff7ecaa00, res=0x9ab640, req=0x99b620) at ../../.dub/packages/vibe-d-master/source/vibe/http/router.d:159

For the sake of completeness the code that actually tries to generate the template is as follows (but the error seems to be with the template itself, as this works fine before adding the offending line to images.dt):

void listImages(HTTPServerRequest req, HTTPServerResponse res)
{
  res.renderCompat!("images.dt", HTTPServerRequest, "req")(req);
}