Dancer::Plugin::Mango - MongoDB connections as provided by Mango.
Tested in a production environment. It's a good idea to read the documentation for Mango as it's async. Which means you must be ready to handle this. In most of my code I'm using the loop function to wait for the server response. However, for inserts, I'm not waiting at all. Handy.
version 0.41
use Dancer; use Dancer::Plugin::Mango; get '/widget/view/:id' => sub { my $mg = mango('mongoa'); my $db = $mg->db('foo'); my $cl = $db->collection('bar'); my $curs = $cl->find({ this => param('id') }); .. } # or get '/widget/view/:id' => sub { my $mg = mango('mongoa')->db('foo')->collection('bar')->find({ this => param('id') }); .. }
Dancer::Plugin::Mango implements the "Mango" driver from the Mojolicious team. It also uses some of the connection pooling features that the Dancer::Plugin::Database module implements. For the most part, read the Mango documentation for full implementation.
Connection details will be taken from your Dancer application config file, and should be specified as follows:
plugins: Mango: host: "myhost" port: 27017 db_name: "mydb" username: "myuser" password: "mypass" w: 1 wtimeout: 1000 credentials: [ mydb, myuser, mypass] [ myotherdb, myotheruser, myotherpass]
or:
plugin: Mango: connections: foohost: host: "foohost" port: 27017 db_name: "mydb" barhost: host: "barhost" port: 27017
The attribute names are verbatim to the attribute names in Mango.
Thanks to Adam Taylor for the original Dancer::Plugin::Mongo. Thanks to the Dancer team for creating a product that keeps me gainfully employed. Thanks to the Mojolicious team for Mango.
This module is HEAVILY reliant on the original Dancer::Plugin::Database code. Most parts in here are unceremoniously copy-pasted from their code. Thanks guys for the work you're doing!
Tyler Hardison <tyler@seraph-net.net>
Collin Seaton cseaton <at> cpan <dot> org
This software is copyright (c) 2014 by Tyler Hardison.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Dancer::Plugin::Mango, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Dancer::Plugin::Mango
CPAN shell
perl -MCPAN -e shell install Dancer::Plugin::Mango
For more information on module installation, please visit the detailed CPAN module installation guide.