Dancer::Plugin::MongoDB - MongoDB connections as provided by Mango.
Horribly under-tested, may induce seizures and sudden death. You have been warned. Additionally, this module will require MongoDB 2.6+. This is primarily because Mango requires it. You will get an error "MongoDB wire protocol version 2 required" if this is not the case.
version 0.34
use Dancer; use Dancer::Plugin::MongoDB; get '/widget/view/:id' => sub { my $mg = mongo('mongoa'); my $db = $mg->database('foo'); my $cl = $db->collection('bar'); my $curs = $cl->find({ this => param('id') }); .. } # or get '/widget/view/:id' => sub { my $mg = mongo('mongoa')->database('foo')->collection('bar')->find({ this => param('id') }); .. }
Dancer::Plugin::MongoDB 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: MongoDB: host: "myhost" port: 27017 db_name: "mydb" username: "myuser" password: "mypass" w: 1 wtimeout: 1000 credentials: [ mydb, myuser, mypass] [ myotherdb, myotheruser, myotherpass]
or:
plugin: MongoDB: 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>
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::MongoDB, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Dancer::Plugin::MongoDB
CPAN shell
perl -MCPAN -e shell install Dancer::Plugin::MongoDB
For more information on module installation, please visit the detailed CPAN module installation guide.