<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>I've been caught by that before. Try <font face="monospace,
monospace">[% entries.$id.item('_id') %]. For some reason (would
interested to learn what), TT doesn't seem to be able to cope
with leading underscores in data structures. You can prove
entries contains data using:</font></p>
<font face="monospace, monospace">[% USE Dumper(Indent=1) %]</font><br>
<font face="monospace, monospace">[% FOREACH id IN entries %]</font><br>
<font face="monospace, monospace"> <pre>[% Dumper.dump(id)
%]</pre></font><br>
[% END %]<br>
<br>
or just <font face="monospace, monospace">[% Dumper.dump(entries)
%]<br>
<br>
</font>
<div class="moz-cite-prefix">On 18/10/2017 06:28, Gavin Colborne
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAL3cdve6EFrVk4bo-V6mLs-6Xv6YSB6o0mTZQ6D+hS0m21Vk_Q@mail.gmail.com">
<div dir="ltr">Hi Dancers,
<div><br>
</div>
<div>I am pretty new to Dancer and really like the light nature
of the framework.</div>
<div><br>
</div>
<div>I am trying to create a route which will show data from a
MongoDB collection and struggling with the syntax.</div>
<div><br>
</div>
<div>I have the following in my app:</div>
<div><br>
</div>
<blockquote style="margin:0 0 0 40px;border:none;padding:0px">
<div>
<div><font face="monospace, monospace">sub connect_mongo {</font></div>
</div>
<div>
<div><font face="monospace, monospace"> my $client =
MongoDB->connect('mongodb://a.b.c.d') or die "Error
connecting to Mongo";</font></div>
</div>
<div>
<div><font face="monospace, monospace"><span style="white-space:pre"> </span>my
$db = $client->get_database( 'lfi-perl' );</font></div>
</div>
<div>
<div><font face="monospace, monospace"><span style="white-space:pre"> </span>return($db);</font></div>
</div>
<div>
<div><font face="monospace, monospace">}</font></div>
</div>
<div><font face="monospace, monospace"><br>
</font></div>
<div>
<div><font face="monospace, monospace">get '/mongo' =>
sub {</font></div>
</div>
<div>
<div><font face="monospace, monospace"> my $db =
connect_mongo();</font></div>
</div>
<div>
<div><font face="monospace, monospace"><span style="white-space:pre"> </span>my
$docs = $db->get_collection( 'Test-Collection' );</font></div>
</div>
<div>
<div><font face="monospace, monospace"><span style="white-space:pre"> </span>my
$all_docs;</font></div>
</div>
<div>
<div><font face="monospace, monospace"> template '<a
href="http://show_mongo.tt" moz-do-not-send="true">show_mongo.tt</a>',
{</font></div>
</div>
<div>
<div><font face="monospace, monospace"> 'entries'
=> $all_docs = $docs->find(),</font></div>
</div>
<div>
<div><font face="monospace, monospace"> };</font></div>
</div>
<div>
<div><font face="monospace, monospace">};</font></div>
</div>
<div><font face="monospace, monospace"><br>
</font></div>
<div><font face="monospace, monospace">Then in my view the
following:</font></div>
<div><font face="monospace, monospace"><br>
</font></div>
<div><font face="monospace, monospace">[% FOREACH id IN
entries.keys.nsort %]</font></div>
<div>
<div><font face="monospace, monospace"> </font></div>
</div>
<div>
<div><font face="monospace, monospace">[% entries.$id._id %]</font></div>
</div>
</blockquote>
<div>
<div><br>
</div>
<div><br>
</div>
<div>I am not able to see any data in my view but am also not
seeing any errors.</div>
<div><br>
</div>
<div>Any examples of getting data from Mongo in Dancer would
be really helpful.</div>
<div><br>
</div>
<div>Thank you in advance,</div>
<div><br>
</div>
<div>Gavin</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br clear="all">
<div>
<div class="gmail_signature">
<div dir="ltr">
<div>
<div dir="ltr">
<div>
<div dir="ltr">Best Regards,<br>
<br>
Gavin Colborne<br>
<br>
Managing Director,<br>
<br>
Tele: 0207 193 2014<br>
Mobile: 0788 400 4339<br>
Skype: gavincolborne<br>
Visit: <a href="http://www.littleforest.co.uk/"
target="_blank" moz-do-not-send="true">www.littleforest.co.uk</a><br>
</div>
<div dir="ltr"><br>
</div>
<div dir="ltr"><a
href="http://www.littleforest.co.uk/"
style="font-family:"Times New
Roman";font-size:medium" target="_blank"
moz-do-not-send="true"><img
src="http://www.littleforest.co.uk/wp-content/uploads/2017/02/1.jpg"
alt="Little Forest LFi"
moz-do-not-send="true"></a><br>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
dancer-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:dancer-users@dancer.pm">dancer-users@dancer.pm</a>
<a class="moz-txt-link-freetext" href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a>
</pre>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
Richard Jones</pre>
</body>
</html>