GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Mojolicious::Plugin::Mongodb(3) User Contributed Perl Documentation Mojolicious::Plugin::Mongodb(3)

Mojolicious::Plugin::Mongodb - Use MongoDB in Mojolicious

version 1.16

Provides a few helpers to ease the use of MongoDB in your Mojolicious application.

    use Mojolicious::Plugin::Mongodb

    sub startup {
        my $self = shift;
        $self->plugin('mongodb', { 
            host => 'localhost',
            port => 27017,
            helper => 'db',
            });
    }

    helper          (optional)  The name to give to the easy-access helper if you want 
                                to change it's name from the default 'db' 

    no_db               (optional)  Don't install the 'db' helper
    no_model            (optional)  Don't install the 'model' helper
    no_coll             (optional)  Don't install the 'coll' helper
    no_find_and_modify  (optional)  Don't install the 'find_and_modify' helper
    no_map_reduce       (optional)  Don't install the 'map_reduce' helper
    no_group            (optional)  Don't install the 'group' helper

All other options passed to the plugin are used to connect to MongoDB.

This plugin helper will return the MongoDB::Connection object, use this if you need to access it for some reason.

This is the name of the default easy-access helper. The default name for it is 'db', unless you have changed it using the 'helper' configuration option. This helper will return either the database you specify, or the last database you specified. You must use this in order to set the database you wish to operate on for those helpers that specify you should.

    sub someaction {
        my $self = shift;

        # select a database 
        $self->db('my_snazzy_database')->get_collection('foo')->insert({ bar => 'baz' });

        # do an insert on the same database
        $self->db->get_collection('foo')->insert({ bar => 'baz' });
    }

This helper allows easy access to a collection. It requires that you have previously selected a database using the 'db' helper. It will return undef if you have not specified a database first.

    sub someaction {
        my $self = shift;

        # get the 'foo' collection in the 'bar' database
        $self->db('bar');
        my $collection = $self->coll('foo');

        # get the 'bar' collection in the 'baz' database
        $self->db('baz');
        my $collection = $self->coll('bar');
    }

This helper functions as a combination of the above, or if you just want to use a different notation. An example usage would be:

    # get the number of items in collection 'bar' in database 'foo'
    my $count = $self->model('foo.bar')->count();

    # if you use dotted collection names, no problem!
    my $system_js_count = $self->model('foo.system.js')->count();

    # if you pass it a regular string without dots, this helper will act like C<coll>.
    my $bar_collection = $self->model('bar');

This helper will set the last selected db to whatever was passed as the database part of the argument, so try not to mix and match "model" with "coll" and "db".

This helper executes a 'findAndModify' operation on the given collection. You must have selected a database using the 'db' helper. See <http://www.mongodb.org/display/DOCS/findAndModify+Command> for supported options. It will return the raw result from the MongoDB driver.

This helper executes a 'mapReduce' operation on the given collection. You must have selected a database using the 'db' helper. All options from <http://www.mongodb.org/display/DOCS/MapReduce> are supported. It will return undef on failure. On success, it will return the raw result from the MongoDB driver, or if you have passed the 'as_cursor' option, it will return a MongoDB::Cursor object for your result collection.

Ben van Staveren, "<madcat at cpan.org>"

Please report any bugs through the web interface at <http://github.com/benvanstaveren/mojolicious-plugin-mongodb/issues> If you want to contribute changes or otherwise involve yourself in development, feel free to fork the Git repository from <https://github.com/benvanstaveren/mojolicious-plugin-mongodb/>.

You can find documentation for this module with the perldoc command.

    perldoc Mojolicious::Plugin::Mongodb

You can also look for information at:

  • AnnoCPAN: Annotated CPAN documentation

    <http://annocpan.org/dist/Mojolicious-Plugin-Mongodb>

  • CPAN Ratings

    <http://cpanratings.perl.org/d/Mojolicious-Plugin-Mongodb>

  • Search CPAN

    <http://search.cpan.org/dist/Mojolicious-Plugin-Mongodb/>

Based on Mojolicious::Plugin::Database because I don't want to leave the MongoDB crowd in the cold.

Thanks to Henk van Oers for pointing out a few errors in the documentation, and letting me know I should really fix the MANIFEST

Copyright 2011, 2012, 2013 Ben van Staveren.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.

2014-05-21 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.